Jump to content

[SOLVED] Checkbox entries are entering zero's into database?


littlevisuals

Recommended Posts

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?  :shrug:

 

 

 

 

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.