Question:
PHP Notice: Undefined inde ERROR?
anonymous
2011-06-27 09:12:35 UTC
Notice: Undefined index: title in C:\xampp\htdocs\mywebsite\Untitled9.php on line 186

Notice: Undefined index: message in C:\xampp\htdocs\mywebsite\Untitled9.php on line 186

Notice: Undefined index: author in C:\xampp\htdocs\mywebsite\Untitled9.php on line 186

mysql_connect("localhost", "root", "");
mysql_select_db("test");
?>

Your Name:

Thread Title:

Thread:






mysql_connect("localhost", "root", "");
mysql_select_db("test");
$time = time();
mysql_query("INSERT INTO threads VALUES(NULL,'$_POST[title]','$_POST[message]','$_POST[author]','0','$time')");

echo "Thread Posted.
Return";
?>
Three answers:
Io amo la musica!
2011-06-27 09:40:47 UTC
Since I've been coding for about four years now I never inserted directly a superglobal variable ($_POST[], $_GET[]) directly into a query. But your main error is that you did not put quotes around the name of the variable.

You did: $_POST[title];

You should do: $_POST['title'];

That's why I also suggest that you set variables to receive the post data first, then use those variables in the query (so that you don't go overboard with the quotes).
anonymous
2016-11-12 11:24:37 UTC
Sorry, yet intelligence has reported GWB, that Heaven is interior the available possession of weapons of mass destruction. ( curiously some bureaucrat study the previous testomony ) . So in a covert operation troops have been moved in to eliminate this coming near near possibility to the united statesA.. they have not got here across something ( yet!!), purely a grey previous guy sitting on a throne, he has been deposed and innovations approximately his upcoming honest trial and execution would be coming near near. interior the intervening time any innovations on the subject of the dominion of Heaven, has been blanked out from the internet to avert "unpatriotic" strikes and comments from the individuals.
?
2011-06-27 11:04:27 UTC
$sql = "insert into `threads`

values (NULL, '" . $_POST['title'] . "', '" . $_POST['mess…

Note the syntax!


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...