Reputation: 134
hi Please help me on this.. i hv created a form & trying to post data to mysql database. but after submitting form i am getting following error..
Notice: Undefined index: month in C:\xampp\htdocs\auto\insert_ac.php on line 14 Notice: Undefined index: listner_name in C:\xampp\htdocs\auto\insert_ac.php on line 15 Notice: Undefined index: rj_name in C:\xampp\htdocs\auto\insert_ac.php on line 16 Notice: Undefined index: channel in C:\xampp\htdocs\auto\insert_ac.php on line 17 Notice: Undefined index: year in C:\xampp\htdocs\auto\insert_ac.php on line 18 Notice: Undefined index: country in C:\xampp\htdocs\auto\insert_ac.php on line 19
& when i check a blank row entry inserted in to my database
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username`
$password=""; // Mysql password
$db_name="auto"; // Database name
$tbl_name="song_request"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Get values from form
$month=mysql_real_escape_string($_POST['month']);
$listner_name=mysql_real_escape_string($_POST['listner_name']);
$rj_name=mysql_real_escape_string($_POST['rj_name']);
$channel=mysql_real_escape_string($_POST['channel']);
$year=mysql_real_escape_string($_POST['year']);
$country=mysql_real_escape_string($_POST['country']);
// Insert data into mysql
$sql="INSERT INTO song_request (month, listner_name, rj_name, channel, year, country)VALUES('$month', '$listner_name', '$rj_name', '$channel', '$year', '$country')";
$result=mysql_query($sql) or die ('error Updating database');
// if successfully insert data into database, displays message "Successful".
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='index.html'>Back to main page</a>";
}
else {
echo "ERROR";
}
// close connection
mysql_close();
?>
Upvotes: 1
Views: 3670
Reputation: 21975
You have no month field on the form that's why you get that error.
$_POST['month']
should be assigned when submitting the form, try to add that field to the form and try again.
Additionally you could check if it's set with isset() and empty() functions.
Upvotes: 0
Reputation: 3041
I don't know what your form looks like, but basically PHP tells you there is no $_POST['month']
. What you really should do is start debugging. See what is in $_POST
and what is not. Try to find out why PHP is telling you that $_POST['month']
is non-existing.
Upvotes: 1