June 17, 201115 yr Hello friends, Dont know why i see this error <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en"> <head> <title><?php echo 'How are you';?></title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <meta name="description" content="" /> <meta name="keywords" content="" /> <meta name="robots" content="all" /> <link rel="stylesheet" href="/templates/uslu_/css/style.css" type="text/css" /> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script> <script src="/links.js" type="text/javascript"></script> <script language="JavaScript" type="text/javascript"> </script> </head> <body> <form action="insert.php" method="post"> First name:<input type="text" name="firstname"/> Last name:<input type="text" name="lastname"/> Age:<input type="text" name="age"/> <input type="submit"/> </form> </body> </html> insert.php <?php $con = mysql_connect("localhost","raj","123"); if (!$con) { die('Could not connect:'.mysql_error()); } mysql_select_db("my_db",$con); $sql="INSERT INTO Persons (FirstName,LastName,Age) VALUES ('$POST[firstname]','$POST[lastname]','$POST[Age]')"; if (!mysql_query($sql,$con)) { die('Error:'.mysql_error()); } echo "1 record added"; mysql_close($con) ?> and when i check the persons table i see this just blank records no data? Edited June 17, 201115 yr by sash_oo7
June 17, 201115 yr The way I do it is to define the variables near the top of the PHP code in the format $FirstName = ($_POST['firstname']) ; $LastName = ($_POST['lastname']) ; $Age = ($_POST['age']) ; and then code the VALUES differently VALUES ('$FirstName','$LastName','$Age')";
June 17, 201115 yr Author ok i tried this <?php/* $con = mysql_connect("localhost","raj","123"); if (!$con) { die('Could not connect:'.mysql_error()); } mysql_select_db("my_db",$con); $sql="INSERT INTO Persons (FirstName,LastName,Age) VALUES ('$POST[firstname]','$POST[lastname]','$POST[age]')"; if (!mysql_query($sql,$con)) { die('Error:'.mysql_error()); } echo "1 record added"; mysql_close($con) ?>*/ <?php $FirstName = ($_POST['firstname']) ; $LastName = ($_POST['lastname']) ; $Age = ($_POST['age']) ; mysql_connect("localhost","raj","123"); mysql_select_db("my_db"); $query="INSERT INTO Persons (FirstName,LastName,Age) VALUES (' $FirstName','$LastName','$Age')"; mysql_query($query) or die('Error adding records'); echo "The record that is added is :" .$FirstName. " " .$LastName. " " .$Age. " ?> and i still get error Parse error: syntax error, unexpected $end, expecting T_VARIABLE or T_DOLLAR_OPEN_CURLY_BRACES or T_CURLY_OPEN in C:\wamp\www\php\insert.php on line 29
June 17, 201115 yr The echo at the end isn't closed off properly. On the last line change: " .$Age. " To: " .$Age;
Create an account or sign in to comment