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.

try a print_r for $_POST at line 19 to confirm what is being posted.

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.