By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,384 Members | 671 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,384 IT Pros & Developers. It's quick & easy.

how to create table for inserting mltiples values in one field?

P: 1
I want to enter multiple checkbox values for parent_history field...for that i have created table...and did php code for inserting value in table...but it shows the Insertion Failed:error....i am not getting what is going wrong?? ,...
my code
Expand|Select|Wrap|Line Numbers
  1. <label>Asthma / Lung Problems</label>
  2.   <input  name="parent_history[]" type="checkbox" ckbox" value="Asthma / Lung Problems" tabindex="7" />
  3. <label>Cancer</label>
  4.  <input name="parent_history[]" type="checkbox"  value="Cancer" tabindex="8" />
  5.  
  6. $media_array = serialize($_POST['parent_history']);
  7.  
  8. $current_symptoms_array = serialize($_POST['current_symptoms']);
  9.  
  10. $sql_insert = "INSERT into `healthinfo`
  11.               (`member_id`, `full_name`, `age`, `height`, `weight`, `waist`, `forearms`, `biceps`, `hip`, `chest`, `parent_history`, `current_symptoms`, `tobacco`, `drugs`, `alcohol`, `outside_food`, `exercise`)
  12.             VALUES
  13.             ('$_SESSION[user_id]','$_SESSION[user_name]',$_POST[age]','$_POST[height]','$_POST[weight]','$_POST[waist]','$_POST[forearms]','$_POST[biceps]','$_POST[hip]','$_POST[chest]','$media_array'
  14.             ,'$current_symptoms_array','$_POST[tobacco]','$_POST[drugs]','$_POST[alcohol]','$_POST[outside_food]','$_POST[exercise]'";        
  15.   mysql_query($sql_insert,$link) or die("Insertion Failed:" . mysql_error());
Oct 19 '11 #1
Share this Question
Share on Google+
1 Reply


Dormilich
Expert Mod 5K+
P: 8,639
there are several SQL syntax errors. I’ll post your SQL with added indenting, maybe you can spot the errors yourself.
Expand|Select|Wrap|Line Numbers
  1. $sql_insert = "
  2. INSERT into `healthinfo`
  3. (
  4.     `member_id`, 
  5.     `full_name`, 
  6.     `age`, 
  7.     `height`, 
  8.     `weight`, 
  9.     `waist`, 
  10.     `forearms`, 
  11.     `biceps`, 
  12.     `hip`, 
  13.     `chest`, 
  14.     `parent_history`, 
  15.     `current_symptoms`, 
  16.     `tobacco`, 
  17.     `drugs`, 
  18.     `alcohol`, 
  19.     `outside_food`, 
  20.     `exercise`
  21. )
  22. VALUES
  23. (
  24.     '$_SESSION[user_id]',
  25.     '$_SESSION[user_name]',
  26.     $_POST[age]',
  27.     '$_POST[height]',
  28.     '$_POST[weight]',
  29.     '$_POST[waist]',
  30.     '$_POST[forearms]',
  31.     '$_POST[biceps]',
  32.     '$_POST[hip]',
  33.     '$_POST[chest]',
  34.     '$media_array',
  35.     '$current_symptoms_array',
  36.     '$_POST[tobacco]',
  37.     '$_POST[drugs]',
  38.     '$_POST[alcohol]',
  39.     '$_POST[outside_food]',
  40.     '$_POST[exercise]'
  41. ";
Oct 19 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.