MySQL Query won't insert

I want to insert a persons status and username into a database. No error shows up, but when I click submit, either the action runs or nothing happens, or the page just refershes. Could anybody help me debug this code? Thanks!

<?php
require("includes/connect.php");
require("includes/redirect.php");
require("includes/userInfo.php");
$status = $_POST['status'];
$upSQL = "INSERT INTO sq_status (UID, Status) VALUES (".$id.", ".$status.")";
$upRun = mysql_query($upSQL);
if(!res){
	die(mysql_error());
	mysql_close($con);
	exit;
}
else{
	header('Location: '. $profile);
	mysql_close($con);
	exit;
}
?>

Here is the HTML, but I don’t think you’ll need it.

    <form id="form1" name="form1" method="post" action="statusUp.php">
      <span id="sprytextarea1">
      <label>
        <textarea name="status" id="status" cols="52" rows="5">What are you doing?</textarea>
      </label>
      <br />
<span class="textareaMaxCharsMsg">Exceeded maximum number of characters.</span></span>
      <p>
        <input type="submit" name="submit" id="submit" value="Update" />
      </p>
    </form>

Could anybody help me debug this code?

Print out variables - are they what you expect?
Print out queries - are they what you expect? do they run (test in phpmyadmin)?

Alright! I found out that it’s the query that’s not working. What would be wrong?

$status = $_POST['status'];
$upSQL = "INSERT INTO sq_status (UID, Status) VALUES (".$id.", ".$status.")";
$upRun = mysql_query($upSQL);

Well the first obvious problem is that your missing quotes around the status string.


$upSQL = "INSERT INTO sq_status (UID, Status) VALUES ($id,'$status')";

I’m also about 99% certain that the label element can’t contain block elements. So your textarea should reside outside the label but that is HTML thing.

Here i want to tell you 3 errors!
1,you design your database table,table id better chose auto_increment,and insert into table not insert table id.
2,you’ll insert into string in php,you should add quote .example:insert into table(name) values("$name")
3,In your form,your textarea should reside outside the label.

was actually my first thought as well.

we need a poll to sort this out, it should have tigers and goats on it.

:smiley

why is that obvious?

post #1 says “I want to insert a persons status and username into a database”

what’s obvious to me is that status is probably numeric while username is string

:smiley:

There’s a textarea in his form called status, prefilled with the text “What are you doing?”

doh!! i totally overlooked that

my excuse is “Here is the HTML, but I don’t think you’ll need it.”

I just need someone to find the error in the code, I don’t know where it is and I need some help. Thanks!

:slight_smile:

I found the problem. IN one of the required files, the connection was closed, so, I couldn’t make the connection.