Jump to content

trouble using insert into


MsKazza

Recommended Posts

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]

Link to comment
Share on other sites


<?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";

?>

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.