Jump to content

Only 1 checkbox gets inserted to mysql?


littlevisuals

Recommended Posts

Hi all,

 

Im really stuck on using checkboxes and ill be happy if someone could help me on the issue.

 

I have 3 tables

 

Catorgories (spelt wrong I know!)

 

id cat

1 Abstract

2 Figurative

3 Landscapes

4 Local Artists

5 Marine

6 Naive Contemporary

7 Originals

8 Still Life

 

Gallery

 

id artist location heading

 

123  vangough  holland    famous_painter

 

 

image_catlu  (where the id FROM gallery should go, and the id FROM cat)

 

cat_ID image_ID

2         0

2              0

7          0

7          0

 

 

The idea is to fetch the different types of catergories and echo as checkboxes for the user to tick.

 

This is part of a form where a user will upload a picture entering details into gallery table, and each pic will be

associated with multiple catergories.  Hence the 2 other tables. 

 

However im stuck because muliple checkboxes can be selected but only 1 gets put into image_catlu and as you can see the image's id in gallery just gets a big fat 0.

 

What it need to do is enter muliple catergories in image_catlu with the image ID in gallery which is in the same script?! :shrug:

 

Sorry if thats confusing  :-\

Link to comment
https://forums.phpfreaks.com/topic/167431-only-1-checkbox-gets-inserted-to-mysql/
Share on other sites

sorry here is the code:

 

<?php
include("connect.php");
   mysql_select_db("artists");
    $cat_ID = $_POST['cat_id']; 
    $image_ID = $_POST['image_id'];
$result = mysql_query("SELECT cat_ID FROM catorgories"); 
$result = mysql_query("SELECT image_ID FROM catorgories");    
    $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());
   
   

?>
<!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,id FROM gallery";
$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="'.$id.'" '.$image_ID.'/></td></tr>'."\n";

}
?>
<tr><td colspan="2"><input type="submit" name="submit" value="add" /></td></tr>
</table>	
</form>
</body>
</html>

Hi, is there anyone who could help me?  Ive been stuck for two days on this and cannot for the life of me figure it out  :-\

 

Im not sure if im even going about it the right way.  I have an image upload form for every picture with name, artist, about etc, and want to include mulitple checkboxes of the different catergories to associate with the picture ( kinda like tags because the catergories are dynamically generated by the admin)

 

Ex table which cat data gets pulled from

id    cat

1    Abstract

2    Figurative

3    Landscapes

 

 

I know there prob needs to be a few tables but most of the checkbox questions on the web are from non-dynamic forms, thus making it hard to find a solution  :confused:

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.