MsKazza Posted November 8, 2011 Share Posted November 8, 2011 Hi all I'm working on a form, i've gotten all the values from the form to the process.php page and it is assigning the correct variables but i can't get it to insert into the database, i know the connection info is correct as i have other page connecting and i can create a recordset on that page. i guess my sql is wrong any help much appreciated. the following is the sql from the database and attached is the process.php page. -- Table structure for table `details` -- CREATE TABLE `details` ( `id` int(6) NOT NULL auto_increment, `first_name` varchar(20) NOT NULL, `sur_name` varchar(20) NOT NULL, `sex` varchar(6) NOT NULL, `age` varchar(3) NOT NULL, `house_no` varchar(5) NOT NULL, `street` varchar(150) NOT NULL, `town` varchar(50) NOT NULL, `bro_sis_cous_friend1` varchar(50) default NULL, `bscf_name1` varchar(150) default NULL, `and` varchar(4) NOT NULL, `bro_sis_cous_friend2` varchar(50) default NULL, `bscf_name2` varchar(150) default NULL, `his_her` varchar(4) default NULL, `him_her` varchar(4) default NULL, `from_name` varchar(150) NOT NULL, `photo_link` varchar(255) default NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=36 ; [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/250702-trouble-using-insert-into/ Share on other sites More sharing options...
Pikachu2000 Posted November 8, 2011 Share Posted November 8, 2011 Post your php script between . . . BBCode tags. Most people won't download an attached file. Quote Link to comment https://forums.phpfreaks.com/topic/250702-trouble-using-insert-into/#findComment-1286224 Share on other sites More sharing options...
MsKazza Posted November 8, 2011 Author Share Posted November 8, 2011 <?php require_once('Connections/book.php'); // Database connect //Parse Values from Coupon.php Form $first_name = mysql_real_escape_string(trim($_POST['first_name'])); $sur_name = mysql_real_escape_string(trim($_POST['sur_name'])); $sex = mysql_real_escape_string(trim($_POST['sex'])); $age = mysql_real_escape_string(trim($_POST['age'])); $house_no = mysql_real_escape_string(trim($_POST['house_no'])); $street = mysql_real_escape_string(trim($_POST['street'])); $town = mysql_real_escape_string(trim($_POST['town'])); $bro_sis_cous_friend1 = mysql_real_escape_string(trim($_POST['bro_sis_cous_friend1'])); $bscf_name1 = mysql_real_escape_string(trim($_POST['bscf_name1'])); $bro_sis_cous_friend2 = mysql_real_escape_string(trim($_POST['bro_sis_cous_friend2'])); $bscf_name2 = mysql_real_escape_string(trim($_POST['bscf_name2'])); $from_name = mysql_real_escape_string(trim($_POST['from_name'])); $photo_link = mysql_real_escape_string(trim($_POST['photo_link'])); if ($sex == 'girl') { $his_her = 'her'; } else { $his_her = 'his'; } if ($sex == 'girl') { $him_her = 'her'; } else { $him_her = 'his'; } $sql="INSERT INTO details (first_name, sur_name, sex, age, house_no, street, town, bro_sis_cous_friend1, bscf_name1, and, bro_sis_cous_friend2, bscf_name2, his_her, him_her, from_name, photo_link) VALUES ('$first_name','$sur_name','$sex','$age','$house_no','$street','$town','$bro_sis_cous_friend1','$bscf_name1','and','$bro_sis_cous_friend2','$bscf_name2','$his_her','$him_her','$from_name','$photo_link')"; echo 'Thank you '. $first_name . ' for entering your details.<br />'; echo 'surname is : '. $sur_name . '.<br />'; echo 'sex is : '. $sex . '.<br />'; echo 'age is: '. $age . ' .<br />'; echo 'bscf friend 1 is : '. $bro_sis_cous_friend1 . '.<br />'; echo 'his_her is : '. $his_her . ' .<br />'; echo 'him_her is : '. $him_her . '.<br />'; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/250702-trouble-using-insert-into/#findComment-1286226 Share on other sites More sharing options...
Pikachu2000 Posted November 8, 2011 Share Posted November 8, 2011 You should be getting an error returned by MySQL for that query string. `and` is a MySQL reserved word. Quote Link to comment https://forums.phpfreaks.com/topic/250702-trouble-using-insert-into/#findComment-1286235 Share on other sites More sharing options...
MsKazza Posted November 8, 2011 Author Share Posted November 8, 2011 yeah i managed to get it connected, and then got the following : Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'and, bro_sis_cous_friend2, bscf_name2, his_her, him_her, from_name, photo_link) ' at line 1 so how can i get it to insert 'and' into the database? thanks Quote Link to comment https://forums.phpfreaks.com/topic/250702-trouble-using-insert-into/#findComment-1286236 Share on other sites More sharing options...
MsKazza Posted November 8, 2011 Author Share Posted November 8, 2011 thank you for your help, i've managed to do it, i just changed it in the database to andy lol all help much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/250702-trouble-using-insert-into/#findComment-1286240 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.