I created database(my_db) and table(persons) in which i used three fields FirstName,LastName and Age. I run below php script it shows error like:
( ! ) Notice: Undefined index: FirstName in C:\wamp\www\insert.php on line 5 Call Stack
Time Memory Function Location
1 0.0007 369800 {main}( ) ..\insert.php:0
( ! ) Notice: Undefined index: LastName in C:\wamp\www\insert.php on line 6 Call Stack
Time Memory Function Location
1 0.0007 369800 {main}( ) ..\insert.php:0
( ! ) Notice: Undefined index: Age in C:\wamp\www\insert.php on line 7 Call Stack
Time Memory Function Location
1 0.0007 369800 {main}( ) ..\insert.php:0 Records added to the database
BELOW IS THE PHP CODE: PLS HELP ME AND THANKS IN ADVANCE
<html>
<body>
<?php
$first=$_POST ['FirstName'];
$last=$_POST ['LastName'];
$a=$_POST ['Age'];
$user_name = "root";
$password = "";
$database = "my_db";
$server = "127.0.0.1";
$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);
if ($db_found) {
$SQL = "INSERT INTO persons(FirstName, LastName, Age) VALUES ('$first', '$last', '$a')";
$result = mysql_query($SQL);
mysql_close($db_handle);
print "Records added to the database";
}
else
{
print "Database NOT Found ";
mysql_close($db_handle);
}
?>
AND HTML FORM IS BELOW:
<html>
<body>
<form action="insert.php" mehtod="POST">
First Name: <input type="text" name="FirstName">
<br />
Last Name:<input type="text" name="LastName">
<br />
Age:<input type="text" name="Age">
<br />
<input type="submit" value="ADD" />
</form>
</body>
</html>