0

Here are the errors im getting.

Notice: Undefined index: address in C:\wamp\www\Insertrecord.php on line 24

Notice: Undefined index: status in C:\wamp\www\Insertrecord.php on line 25

Notice: Undefined index: religion in C:\wamp\www\Insertrecord.php on line 26

Notice: Undefined index: region in C:\wamp\www\Insertrecord.php on line 27

Notice: Undefined index: zipcode in C:\wamp\www\Insertrecord.php on line 28

Notice: Undefined index: cpnumber in C:\wamp\www\Insertrecord.php on line 29
Insert Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Code, CP Number) VALUES ( '', '', '', '', '', '', '', '', '')' at line 1

Heres my code:

<html>
<head>
<title>Record Entry</title>
</head>

<body>

<center>

<br><br>
<br><br>
<br><br>
<br><br>


<b>
<?php

/* Variables Here */

$fname=$_POST['fname'];
$age=$_POST['age'];
$birthday=$_POST['birthday'];
$address=$_POST['address'];
$status=$_POST['status'];
$religion=$_POST['religion'];
$region=$_POST['region'];
$zipcode=$_POST['zipcode'];
$cpnumber=$_POST['cpnumber'];

/* Database Connection Start */

$con = mysql_connect('localhost', 'root' , '');
	
if (! $con)
	{
die(mysql_error());
	}
mysql_select_db("database" , $con) or die("Select Error: ".mysql_error());
$result=mysql_query("INSERT INTO Record (Name, Age, Birthday, Address, Status, Religion, Region, Zip Code, CP Number) VALUES (
'$fname',
'$age', 
'$birthday',
'$address', 
'$status',
'$religion', 
'$region',
'$zipcode', 
'$cpnumber')") or die("Insert Error: ".mysql_error());
mysql_close($con);

/* Database Connection Ends */

print "Record successfully added.";
?>
<br><br>
<form method="POST" action="Insertform.php">
<input type="submit" value="Insert Another Record">
</form>
<br><br>

<form method="POST" action="index.php">
<input type="submit" value="Back to Main Menu">
</form>

</center>
</body>
</html>

My Fields are right. I just don't get it, the first 3 $_POST are correct.

2
Contributors
3
Replies
6
Views
7 Years
Discussion Span
Last Post by abelingaw
0

I think this is normal.

Maybe the vars aren't properly set. (?)

COuld u modify my code.

Im a starter and im only at GET and POST method right now

0

Oh now i get it.

I have to use ISSET.

$fname=isset($_POST['fname']) ? $_POST["fname"] : "";
	$age=isset($_POST['age']) ? $_POST["age"] : "";
	$birthday=isset($_POST['birthday']) ? $_POST["birthday"] : "";
	

	$address=isset($_POST['address']) ? $_POST["address"] : "";
	$status=isset($_POST['status']) ? $_POST["status"] : "";
	$religion=isset($_POST['religion']) ? $_POST["religion"] : "";
	$region=isset($_POST['region']) ? $_POST["region"] : "";
	$zipcode=isset($_POST['zipcode']) ? $_POST["zipcode"] : "";
	$cpnumber=isset($_POST['cpnumber']) ? $_POST["cpnumber"] : "";

$con = mysql_connect('localhost', 'root' , '');

//TO MODS
//POST READY FOR DELETION

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.