Jump to content

Inserting data into table


seany02

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.