Page 1 of 1

CAn not insert $_POST into Mysql: "UNDEFINED INDEX"

Posted: Sun Jun 16, 2002 4:15 am
by dawn
HI.I've tried those echo $_POST['textfield1'];
without any problems on PHP 4.21 but when I try to add value of those forms to MYSQL it cause UNDEFINED index error .I hope I can get some hint or some help from you,thanks.Here is the code.
<?
$dbHost = "localhost";
$dbUser = "dawn";
$dbPass = "dawn";
$dbName = "news";
$table = "newstable";
$connect = @mysql_connect ($dbHost, $dbUser, $dbPass);
if (!$connect)
{
echo "result".urlencode("Error Cannot connect to SQL Server");
exit;
}
if (!@mysql_select_db ($dbName))
{
echo "result=".urlencode("Error Cannot Select DATABASE");
};
$result = mysql_query("INSERT INTO newstable (headline, body) VALUES ({$_POST['addnewsheadline']},{$_POST['addnewsbody']})");
if ($result)
{
print "result=success!";}
mysql_close($connect);
?>
ERrror: PHP Notice: Undefined index: addnewsheadline in C:\Inetpub\wwwroot\php\addnews.php on line 17 PHP Notice: Undefined index: addnewsbody in C:\Inetpub\wwwroot\php\addnews.php on line 17
I think the error is resulted from $_POST varible.ANd I do NOT know how to fix this.
Help me please.
THanks.

Posted: Sun Jun 16, 2002 5:13 am
by twigletmac
Try putting,

Code: Select all

echo '<pre>';
print_r($_POST);
echo '</pre>';
at the top of the script to find out what's in the $_POST array.

Mac