doforumda Posted April 9, 2009 Share Posted April 9, 2009 hi i need help in the following code. i want to insert data into the mysql database using php using html form but it is giving this error Parse error: parse error in C:\wamp\www\examples\insertinto.php on line 12 how can i solve this problem Quote Link to comment https://forums.phpfreaks.com/topic/153291-need-help/ Share on other sites More sharing options...
ratcateme Posted April 9, 2009 Share Posted April 9, 2009 the is a problem with your code on line 12 can you post say the first 15 lines of your code. you can remove any info like database login info if you want Scott. Quote Link to comment https://forums.phpfreaks.com/topic/153291-need-help/#findComment-805331 Share on other sites More sharing options...
doforumda Posted April 9, 2009 Author Share Posted April 9, 2009 here is the code <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>insertinto</title> </head> <body> <?php $db = mysql_connect("localhost","username","password"); mysql_select_db("nu",$db); $query = "insert into student (name, fname, age, phone) values ('".$name."','".$fname"','".$age."','".$phone."')" or die(mysql_error()); $run = mysql_query($query) or die(mysql_error()); echo "Your data is entered correctly......"; ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/153291-need-help/#findComment-805335 Share on other sites More sharing options...
ratcateme Posted April 9, 2009 Share Posted April 9, 2009 errors like that you just need to read and re-read the line until you can pick something up you are missing a . after $fname also you only the the "or dir" part on the end of a mysql_query call not when you are putting the query into a var Scott. Quote Link to comment https://forums.phpfreaks.com/topic/153291-need-help/#findComment-805336 Share on other sites More sharing options...
doforumda Posted April 9, 2009 Author Share Posted April 9, 2009 thanks Scott Quote Link to comment https://forums.phpfreaks.com/topic/153291-need-help/#findComment-805344 Share on other sites More sharing options...
revraz Posted April 9, 2009 Share Posted April 9, 2009 There is no reason to concatenate in your sql statement either. $query = "insert into student (name, fname, age, phone) values ('$name','$fname','$age','$phone')"; Quote Link to comment https://forums.phpfreaks.com/topic/153291-need-help/#findComment-805485 Share on other sites More sharing options...
redarrow Posted April 9, 2009 Share Posted April 9, 2009 bit better with database protection. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>insertinto</title> </head> <body> <?php $db = mysql_connect("localhost","username","password"); mysql_select_db("nu",$db); $query="insert into student(name, fname, age, phone)values('".mysql_real_escape_string($_POST['name'])."','".mysql_real_escape_string($_POST['fname'])."','".mysql_real_escape_string($_POST['age'])."','".mysql_real_escape_string($_POST['phone'])."')"; $run = mysql_query($query) or die(mysql_error()); echo "Your data is entered correctly......"; ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/153291-need-help/#findComment-805499 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.