Php not inserting checkbox data in mysql
Posted: Tue Jul 28, 2009 10:02 am
Hi all im having serious issues with this script. At current the script inserts a checked category number into the table images_catlu into the cat_ID field.
How do I modyfy it to insert multiple checked data into the table?
Here is the code, any help would be awesome
How do I modyfy it to insert multiple checked data into the table?
Here is the code, any help would be awesome
Code: Select all
<?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>