Checkboxes in mysql
I have a new problem involving checkboxes and placing their values into a mysql database.
if(isset($submit)){
//update the database with the information
$id = getUserID($cookie_name);
$sql = "UPDATE daysweek1 set 1m='$1m', 1t='$1t', 1w='$1w', 1th='$1th', 1f='$1f' where id=$id";
$db->query($sql);
}
On submission, update the table.
<input type='checkbox' name='1m' value='checked' ".$user_weekoneinfo['1m'].">
<input type='checkbox' name='1t' value='checked' ".$user_weekoneinfo['1t'].">
<input type='checkbox' name='1w' value='checked' ".$user_weekoneinfo['1w'].">
<input type='checkbox' name='1th' value='checked' ".$user_weekoneinfo['1th'].">
<input type='checkbox' name='1f' value='checked' ".$user_weekoneinfo['1f'].">
Here are the fields.
And when I submit the form, this is what the values looks like:
$1m $1t $1w $1th $1f
For some reason the value of "checked" isn't being sent to the field name. Anyone know what to do here?
timjpriebe posted this at 12:52 — 20th December 2004.
He has: 2,667 posts
Joined: Dec 2004
Are you assigning the values of the checkboxes to the variables $1m, $1t, $1w, $1th and $1f ? Just because the checkboxes are named that doesn't mean you don't have to still pull the values of those checkboxes into a variable.
Also, from this short excerpt of code, I'm not entirely sure what language you're working in. Knowing that could help us diagnose the problem.
Tim
http://www.tandswebdesign.com
CptAwesome posted this at 18:56 — 20th December 2004.
He has: 370 posts
Joined: Dec 2004
In the mysql query, you don't have ``s around the field or table names.
timjpriebe posted this at 19:55 — 20th December 2004.
He has: 2,667 posts
Joined: Dec 2004
It should still work, though. I leave those off all the time.
Tim
http://www.tandswebdesign.com
CptAwesome posted this at 20:24 — 20th December 2004.
He has: 370 posts
Joined: Dec 2004
Looks like PHP that he is using, but not sure.
try also giving us the final query (echo $sql)
Also make sure that you are able to access $_POST and $_GET variables, some servers by default don't make $var = $_GET['var']/$_POST['var']
airoid3000 posted this at 03:35 — 21st December 2004.
They have: 71 posts
Joined: Mar 2004
I guess you can't have the first character in a mysql field a number? I changed all my fields to different names with the numbers at the end instead of the beginning and it worked. I never knew this.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.