Jump to content

Set Categories


daebat

Recommended Posts

I am creating a submission form for somebody to come in and submit products.  These products are separated by brand.  How can I get them to display according to the brand?

 

Here is the form code:

 

<?

include("../include/session.php");

?>


<?php


if ($submit) {


$sql = "UPDATE productimages SET
title='".$_POST['title']."', 
upjpg='".$_POST['upjpg']."',
uptiff='".$_POST['uptiff']."',
uppng='".$_POST['uppng']."', 
chungshi='".$_POST['chungshi']."',   
stretchwalker='".$_POST['stretch_walker']."',
akaishi='".$_POST['akaishi']."', 
bellamargiano='".$_POST['bellamargiano']."',
mbt='".$_POST['mbt']."', 
upthumb='".$_POST['upthumb']."'
where id ='".mysql_real_escape_string($_POST['id'])."'";

	$result = mysql_query($sql) or die(mysql_error());


print("Product Added");





} else {


$result = mysql_query("SELECT * FROM productimages WHERE id = '$id'");
 while ($row=mysql_fetch_array($result)) {
 	$id = $row[id];
 	$uptiff = $row[uptiff];
 	$upjpg = $row[upjpg];
 	$uppng = $row[uppng];
 	$chungshi = $row[chungshi];
 	$stretchwalker = $row[stretchwalker];
 	$akaishi = $row[akaishi];
 	$bellamargiano = $row[bellamargiano];
 	$mbt = $row[mbt];
 	$upthumb = $row[upthumb];

 }

print ("



<form method=post action=productimages.php>
Product Title:<br>
<input type=text name=title size=60><br><br>


Choose Categories that this story is relevant to:<br>

<input type=checkbox name=chungshi value=1> Chung Shi<br>
<input type=checkbox name=stretchwalker value=1> Stretchwalker<br>
<input type=checkbox name=akaishi value=1> Akaishi<br>
<input type=checkbox name=bellamargiano value=1> Bellamargiano<br>
<input type=checkbox name=mbt value=1> MBT<br><br>


<table width=500 cellpadding=0 cellspacing=0>



<tr><td colspan=2 class=top><strong>Images</strong></td></tr>

<tr><td>Upload JPG</td><td><br><input type=file name=upjpg></td></tr>
<tr><td colspan=2 class=top> </td></tr>
<tr><td>Upload TIFF</td><td><br><input type=file name=uptiff> </td></tr>
<tr><td colspan=2 class=top> </td></tr>
<tr><td>Upload PNG</td><td><br><input type=file name=uppng> </td></tr>
<tr><td colspan=2 class=top> </td></tr>
<tr><td>Upload Thumbnail</td><td><br><input type=file name=upthumb> </td></tr>
</table>


<br>
<input type=submit name=submit value=submit><br>
<br>
</form>

");




}

?>

 

Link to comment
https://forums.phpfreaks.com/topic/176982-set-categories/
Share on other sites

Escape all of your data, not just the ID.  Consider using a separate table for categories, this will enable you to more easily add/remove categories and sort by them.  If you don't know what database normalization is, read about it, it'll help convince you.  Once you've done this, your sql to sort by category could be:

 

SELECT * FROM `products` INNER JOIN `categories` ON `products`.`category` = `categories`.`id` ORDER BY `category` ASC

Link to comment
https://forums.phpfreaks.com/topic/176982-set-categories/#findComment-933190
Share on other sites

So you're saying I should put:

 

if ($submit) {


$sql = "UPDATE productimages SET
title='".mysql_real_escape_string($_POST['title']."', 
upjpg='".mysql_real_escape_string($_POST['upjpg']."',
uptiff='".mysql_real_escape_string($_POST['uptiff']."',
uppng='".mysql_real_escape_string($_POST['uppng']."', 
chungshi='".mysql_real_escape_string($_POST['chungshi']."',   
stretchwalker='".mysql_real_escape_string($_POST['stretch_walker']."',
akaishi='".mysql_real_escape_string($_POST['akaishi']."', 
bellamargiano='".mysql_real_escape_string($_POST['bellamargiano']."',
mbt='".mysql_real_escape_string($_POST['mbt']."', 
upthumb='".mysql_real_escape_string($_POST['upthumb']."'
where id ='".mysql_real_escape_string($_POST['id'])."'";

	$result = mysql_query($sql) or die(mysql_error());

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/176982-set-categories/#findComment-933207
Share on other sites

I am getting

Column 'id' in field list is ambiguous
.

 

$data = mysql_query("SELECT `id` FROM `productimages` INNER JOIN `pimagecategories` ON `productimages`.`category` = `categories`.`id` WHERE `categories`.`id` = 1;") or die(mysql_error());

 

I know it is because I have two 'id' fields but I'm not sure what to do to the code to make it work.

Link to comment
https://forums.phpfreaks.com/topic/176982-set-categories/#findComment-936181
Share on other sites

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.