I am developing a web application that allows a user to add entries to a MySQL database through a web form. The web form posts to the same page, some PHP code captures that data and sends it to MySQL. For whatever reason, nothing ever makes it to MySQL. This is the code I have so far that isn’t working:
<?php
include("config.inc.php");
$Name=$_POST['AddName'];
$Group=$_POST['AddGroup'];
$Grade=$_POST['AddGrade'];
$Position=$_POST['AddPosition'];
$Email=$_POST['AddEmail'];
$HomeAddress=$_POST['AddHomeAddress'];
$City=$_POST['AddCity'];
$State="SC";
$Zip=$_POST['AddZIP'];
$CellPhone=$_POST['AddCellNumber'];
$HomePhone=$_POST['AddHomeNumber'];
$FirstPeriod=$_POST['AddFirstPeriod'];
$SecondPeriod=$_POST['AddSecondPeriod'];
$ThirdPeriod=$_POST['AddThirdPeriod'];
$FourthPeriod=$_POST['AddFourthPeriod'];
$FifthPeriod=$_POST['AddFifthPeriod'];
$SixthPeriod=$_POST['AddSixthPeriod'];
$SeventhPeriod=$_POST['AddSeventhPeriod'];
$Homeroom=$_POST['AddHomeroom'];
$dbpassword=$_POST['AddPassword'];
$con = mysql_connect("127.0.0.1","$username","******");
if (!$con)
{
die();
}
mysql_select_db("$database", $con);
$sql="INSERT INTO names (Name,Grp,Grade,Position,Email,HomeAddress,City,State,Zip,CellPhone,HomePhone,FirstPeriod,SecondPeriod,ThirdPeriod,FourthPeriod,FifthPeriod,SixthPeriod,SeventhPeriod,Homeroom)
VALUES('$Name','$Group','$Grade','$Position','$Email','$HomeAddress,'$City','$State','$Zip','$CellPhone','$HomePhone','$FirstPeriod','$SecondPeriod','$ThirdPeriod','$FourthPeriod','$FifthPeriod','$SixthPeriod','$SeventhPeriod','$Homeroom')";
if (!mysql_query($sql,$con))
{
die();
}
echo "1 record added";
mysql_close($con)
?>
</body>
</html>
Try this and see what it says: