littlevisuals Posted July 15, 2009 Share Posted July 15, 2009 Hello everyone, I still have a lot to learn, which im trying but I cant figure out why multiple selected catergories are entering zeros into my cat_ID and image_ID fields? Its probable best if I link to my original problem over@mysql http://www.phpfreaks.com/forums/index.php/topic,260546.0.html. Ive now made a lookup table similar to xtopolis' instructions. Here is the code (from the checkbox tut) and ive made a few changes. <?php include("connect.php"); mysql_select_db("artists"); $cat_ID = $_POST['id']; $image_ID = $_POST['id']; $query = "INSERT INTO image_catlu (cat_ID, image_ID) VALUES ('$cat_ID', '$image_ID')"; $results = mysql_query($query) or die ("Could not execute query : $query." . mysql_error()); if ($results) { echo "Details added."; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>CHECKBOX</title> </head> <body> <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post"> <table> <tr> </tr> <?php $sql = "SELECT id,cat FROM catorgories ORDER by id ASC"; "SELECT id FROM artists"; $result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR); while(list($id,$cat)=mysql_fetch_row($result)){ echo '<tr><td>'.$cat.'</td><td><input type="checkbox" name="cat_ID[]" value="'.$cat_ID.'" '.$image_ID.'/></td></tr>'."\n"; } ?> <tr><td colspan="2"><input type="submit" name="submit" value="add" /></td></tr> </table> </form> </body> </html> Is there something stupid im doing wrong? Link to comment https://forums.phpfreaks.com/topic/166063-solved-checkbox-entries-are-entering-zeros-into-database/ Share on other sites More sharing options...
Bricktop Posted July 15, 2009 Share Posted July 15, 2009 Change: $cat_ID = $_POST['id']; $image_ID = $_POST['id']; to: $cat_ID = $_POST['cat_id']; $image_ID = $_POST['cat_id']; And then change: echo '<tr><td>'.$cat.'</td><td><input type="checkbox" name="cat_ID[]" value="'.$cat_ID.'" '.$image_ID.'/></td></tr>'."\n"; to: echo '<tr><td>'.$cat.'</td><td><input type="checkbox" name="cat_id" value="'.$cat_ID.'" '.$image_ID.'/></td></tr>'."\n"; Link to comment https://forums.phpfreaks.com/topic/166063-solved-checkbox-entries-are-entering-zeros-into-database/#findComment-875801 Share on other sites More sharing options...
littlevisuals Posted July 15, 2009 Author Share Posted July 15, 2009 Thanks Bricktop, sorry it took me long to get back Link to comment https://forums.phpfreaks.com/topic/166063-solved-checkbox-entries-are-entering-zeros-into-database/#findComment-876087 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.