Connecting Tech Pros Worldwide Forums | Help | Site Map

Checkboxes into mySQL wont work (for me)!

faugustin's Avatar
Newbie
 
Join Date: Aug 2009
Location: Sweden
Posts: 5
#1: Sep 18 '09
Hello, I'm stuck in my developing of a filmcatalogue-type db. I have 3 tables and 2 html-forms. The form for the films is working ok- it's based on text inputs.
BUT I can't get the form for "genres" to work; I want to use checkboxes with 11 genre/types, because a film must be specified with...say 3 attributes (e.g. drama, action, war...). I want the result to be boolean in the table (1 or 0, not null) and select the 1's in PHP to present it all in html. The third table is shared (filmID, title, genre).
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $con = mysql_connect("localhost","root","");
  3. if (!$con)
  4.   {
  5.   die('Could not connect: ' . mysql_error());
  6.   }
  7.  
  8. mysql_select_db("filmarkiv", $con);
  9.  
  10. $sql="INSERT INTO genre_film (drama, thriller, action, dokumentär, kärlek, humor, krig, skräck, kriminalare, historia, politik)
  11. VALUES
  12. ('$_POST[drama]','$_POST[thriller]','$_POST[action]','$_POST[dokumentär]','$_POST[kärlek]','$_POST[humor]','$_POST[krig]','$_POST[skräck]','$_POST[kriminalare]','$_POST[historia]','$_POST[politik]')";
  13. if (!mysql_query($sql,$con))
  14.   {
  15.   die('Error: ' . mysql_error());
  16.   }
  17. echo "1 film uppdaterad";
  18. mysql_close($con)
  19. ?>
Grateful for help!
Attached Thumbnails
filmer_tbl.jpg   genre_tbl.png  

ssnaik84's Avatar
Member
 
Join Date: Aug 2009
Location: Bengaluru, India
Posts: 122
#2: Sep 18 '09

re: Checkboxes into mySQL wont work (for me)!


use boolean data type instead of tinyint for checkbox result
faugustin's Avatar
Newbie
 
Join Date: Aug 2009
Location: Sweden
Posts: 5
#3: Sep 18 '09

re: Checkboxes into mySQL wont work (for me)!


OK, thanx, I'll do that but I have problems before it gets that far- in the form and php. How do I handle the checkboxes values, to post them into the table "genre", with php?
Reply

Tags
checkbox, mysql, php