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.
CAn not insert $_POST into Mysql: "UNDEFINED INDEX"
Moderator: General Moderators
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Try putting,
at the top of the script to find out what's in the $_POST array.
Mac
Code: Select all
echo '<pre>';
print_r($_POST);
echo '</pre>';Mac