seany02 Posted April 22, 2009 Share Posted April 22, 2009 Im trying to insert data into a table. I get a parse error in the browser when i try to run the script. The parse error doesnt tell me whats expected or unexpected. Any ideas? thanks <?php if (isset($_REQUEST['Submit'])) { # THIS CODE TELL MYSQL TO INSERT THE DATA FROM THE FORM INTO YOUR MYSQL TABLE $sql = "INSERT INTO $db_table(contact_id,contact_name,contact_address,telephone_no,email) values ('".mysql_real_escape_string(stripslashes($_REQUEST['contact_id']))."','"mysql_real_escape_string(stripslashes($_REQUEST['contact_name']))."','"mysql_real_escape_string(stripslashes($_REQUEST['contact_address']))."','"mysql_real_escape_string(stripslashes($_REQUEST['telephone_no']))."','".mysql_real_escape_string(stripslashes($_REQUEST['email']))."')"; if($result = mysql_query($sql ,$db)) { echo '<h1>Thank you</h1>Your information has been entered into our database<br><br><img src="http://www.webune.com/images/headers/default_logo.jpg"'; } else { echo "ERROR: ".mysql_error(); } } else { ?> Link to comment https://forums.phpfreaks.com/topic/155218-inserting-data-into-table/ Share on other sites More sharing options...
jackpf Posted April 22, 2009 Share Posted April 22, 2009 Well what's the error then? Link to comment https://forums.phpfreaks.com/topic/155218-inserting-data-into-table/#findComment-816567 Share on other sites More sharing options...
seany02 Posted April 22, 2009 Author Share Posted April 22, 2009 I don't know what the error is. Thats the problemo Link to comment https://forums.phpfreaks.com/topic/155218-inserting-data-into-table/#findComment-816573 Share on other sites More sharing options...
jackpf Posted April 22, 2009 Share Posted April 22, 2009 I get a parse error in the browser when i try to run the script. What is that error? Link to comment https://forums.phpfreaks.com/topic/155218-inserting-data-into-table/#findComment-816577 Share on other sites More sharing options...
seany02 Posted April 22, 2009 Author Share Posted April 22, 2009 Parse error: parse error in C:\xampp\htdocs\contacts.php on line 61 line 61 is the fourth line of the code i posted Link to comment https://forums.phpfreaks.com/topic/155218-inserting-data-into-table/#findComment-816581 Share on other sites More sharing options...
radi8 Posted April 22, 2009 Share Posted April 22, 2009 Here it is: original SQL: <?php $sql = "INSERT INTO $db_table(contact_id,contact_name,contact_address,telephone_no,email)values ('".mysql_real_escape_string(stripslashes($_REQUEST['contact_id']))."','"mysql_real_escape_string(stripslashes($_REQUEST['contact_name']))."','"mysql_real_escape_string(stripslashes($_REQUEST['contact_address']))."','"mysql_real_escape_string(stripslashes($_REQUEST['telephone_no']))."','".mysql_real_escape_string(stripslashes($_REQUEST['email']))."')"; ?> corrected SQL: <?php $sql = "INSERT INTO $db_table(contact_id,contact_name,contact_address,telephone_no,email)values ('".mysql_real_escape_string(stripslashes($_REQUEST['contact_id']))."','".mysql_real_escape_string(stripslashes($_REQUEST['contact_name']))."','".mysql_real_escape_string(stripslashes($_REQUEST['contact_address']))."','".mysql_real_escape_string(stripslashes($_REQUEST['telephone_no']))."','".mysql_real_escape_string(stripslashes($_REQUEST['email']))."')"; ?> you forgot to add several "." before the mysql_real_escape_string(...) statements Link to comment https://forums.phpfreaks.com/topic/155218-inserting-data-into-table/#findComment-816585 Share on other sites More sharing options...
jackpf Posted April 22, 2009 Share Posted April 22, 2009 You should put your posted data into variables. Makes it much easier to spot errors like this. & nice catch radi8. Link to comment https://forums.phpfreaks.com/topic/155218-inserting-data-into-table/#findComment-816624 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.