MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 12th, 2000, 07:57 PM
ph0123 ph0123 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Posts: 4 ph0123 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
This question is similar to one posted previously by icewind0. That person asked about storing responses from a select element on a form. The response to that was to create a table with the limited responses, etc. What about check boxes? I would imagine you could create a table to store all the possible answers, but how would you associate a variable number of answers with the user who answered them? For example, on a form that says: check all the sports you like, there could be 12 sports listed. Each user who fills out the form could pick 0, 1, or up to 12. If you have a table with the users data in it, what is the right/best way to store this type of input?

Thanks for any help.


Reply With Quote
  #2  
Old July 13th, 2000, 06:03 AM
releasedj releasedj is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Location: London
Posts: 46 releasedj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
Create a table in your db called sports for example:

CREATE TABLE sports (
like SET('football', 'tennis','rugby')
);

This field will now only take these three sporting values.

Next here's some code to input into the table

********************* HTML ******************

<?
print "<HTML>n";
print "<HEAD>n";
print "</HEAD>n";

print "<BODY>n";
print("Choose a sport that you like<BR>n");

print("<FORM ACTION="sportphp.php3">n");


print("<INPUT TYPE="checkbox" NAME="sport[]" VALUE="football">Football");

print("<INPUT TYPE="checkbox" NAME="sport[]" VALUE="tennis">Tennis");

print("<INPUT TYPE="checkbox" NAME="sport[]" VALUE="rugby">Rugby");


print("<INPUT TYPE="submit">n");
print("</FORM>n");
print("</BODY>n");
print("</HTML>n");
?>

On submit this will create an array '$sport[]' with the values of the 3 sports.

****************** php ********************

<?
if(isset($sports))
{
$mylink = mysql_connect('localhost','user','password');


$query = "INSERT INTO sports(like) VALUES('$sports[0]','$sports[1]','$sports[2]')";

$result = mysql_db_query('dbname',$query, $mylink) or die("Could not execute query");
}
else
{
print("No items were selected!");
}
?>

This should work although I just typed it now and haven't checked it for errors.

Kelvin

Reply With Quote
  #3  
Old July 13th, 2000, 04:30 PM
ph0123 ph0123 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Posts: 4 ph0123 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks for the comprehensive reply, but that doesn't work. I get an error that says column count does not equal value count when I try the insert. Is it necessary to build a comma separated list of the values then insert that?

Thanks.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > what about checkboxes and mysql?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT