If setting a "check for submit" sort of thing bypassed the error, then the error is in the code to update the database and the "if" isn't likely processing at all... Try this to further check:
PHP Code:
<?php if (isset ($_POST['submit']) ) { echo('<h1 style="color:#F00;">Amanda was wrong.</h1>');
$TITLE = $_POST['TITLE'];
... etc etc etc
}else{
echo('<h1 style="color:#F00;">Amanda was right.</h1>'); }
If your page says "Amanda was right" when you process the form, then you know that your "if" part isn't processing, which means it's not getting the "submit" order otherwise I don't know what to tell you. Also, the page will probably say "Amanda was right" before you process the form too, so ignore it until you actually hit submit.
Also, just a note: the "title" variable will enter into the database with a space on either side when you submit this form... it's ok to have the apostrophe up against the quotation ( '".$TITLE."' rather than ' ".$TITLE." ' )
So then the error isn't in the function here, or else it would've displayed one of the two messages. If it doesn't show either one, then it doesn't even get this far; the error is somewhere else in your file. It has to be in something before this stuff even happens...
Well then unfortunately I don't know what to tell you.
I would think that it might work better if there was a doctype and regular page framework for the form (that's what mine all do) so I'm not sure where yours is misbehaving.
<?php
if (isset ($_POST['submit']) )
{
echo('<h1 style="color:#F00;">Amanda was wrong.</h1>');
$TITLE = $_POST['TITLE'];
mysql_connect ("localhost", "admin", "pass") or die ('Connect error: ' .mysql_error());
mysql_select_db ("database") or die ('Select DB error: ' . mysql_error());
// NULL should not be quoted, as I presume you want to use the SQL keyword, not the string literal?
$query="INSERT INTO db_table (ID, TITLE)VALUES (NULL, ' ".$TITLE." ')";
mysql_query($query) or die ("Error updating database:<pre>$query</pre>");
echo "Database updated with: ".$TITLE;
}
else
{
echo('<h1 style="color:#F00;">Amanda was right.</h1>');
}
?>
Note, once you're done debugging, most of that "or die()" stuff should be converted into tests of return values and logging any debug info instead of exposing it to users, using a more user-friendly error message.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Bookmarks