inventory page help

I have php code for products to be added to the msql database but how can I code it to add to particular category pages?

I’ve attached my code.

Thanks!


Inventory.txt (1.31 KB)

I’m posting the code in you text file, just makes it easier to red, since it’s so short. I don’t understand what you mean by “but how can I code it to add to particular category pages?” Can you clarify that better?

[php]<?php
// Parse the form data and add inventory item to the system
if (isset($_POST[‘product_name’])) {

$product_name = mysql_real_escape_string($_POST['product_name']);
$price = mysql_real_escape_string($_POST['price']);
$category = mysql_real_escape_string($_POST['category']);
$subcategory = mysql_real_escape_string($_POST['subcategory']);
$details = mysql_real_escape_string($_POST['details']);
// See if that product name is an identical match to another product in the system
$sql = mysql_query("SELECT id FROM allproducts WHERE product_name='$product_name' LIMIT 1");
$productMatch = mysql_num_rows($sql); // count the output amount
if ($productMatch > 0) {
	echo 'Sorry you tried to place a duplicate "Product Name" into the system, <a href="inventory_list.php">click here</a>';
	exit();
}
// Add this product into the database now
$sql = mysql_query("INSERT INTO allproducts (product_name, price, details, category, subcategory, date_added) 
    VALUES('$product_name','$price','$details','$category','$subcategory',now())") or die (mysql_error());
 $pid = mysql_insert_id();
// Place image in the folder 
$newname = "$pid.jpg";
move_uploaded_file( $_FILES['fileField']['tmp_name'], "../inventory_images/$newname");
header("location: inventory_list.php"); 
exit();

}
?>[/php]

Sorry for being so vague … I have 3 separate ‘category’ pages but when I add an item via the inventory list it appears in all the category pages. I know this is because it’s using the ‘allproducts’ page but I’m not sure how to filter to appropriate category. Hope this makes things clearer! Thanks

Based on what I see, you have defined a Category and Subcategory on the upload. (I’m not sure of the values of those fields) but on the assumption they are populated properly, that will mean we will need to see the code for the category page, so we can see how it filters based on category.

Thanks Karma,
I’ve managed to get it working … here’s my new code …

<?php // Connect to the MySQL database include "storescripts/connect_to_mysql.php"; if (isset($_GET['category']) ) { $title = " Our " . ucwords ($_GET['category']) . " Products" ; } else { $title = 'All Products'; } $sql = "SELECT * FROM allproducts"; if (isset($_GET['category']) ) { $sql .= " WHERE category = '" . $_GET['category'] . "'"; } $sql .= " ORDER BY id DESC LIMIT 15"; $sql = mysql_query($sql); $i=0; $dynamicList = ''; while($row = mysql_fetch_array($sql)) { $id = $row["id"]; $product_name = $row["product_name"]; $price = $row["price"]; //$date_added = strftime("%b %d, %Y", strtotime($row["date_added"])); if ($i % 3 == 0) { // 3 across $dynamicList .= ' '; } $dynamicList .= ' '; $i++; } $dynamicList .= '
<img style="border:#042502 2px solid;" ' . $product_name .'
' . "£".$price .'
View Product Details
'; mysql_close(); // closes any connections ?> Laser Cut Crafts Products
<?php include_once ("template_header.php");?>
  <hnav>
		<ul>
			<li><a href="index.php"><img src="buttons/Home1.png" alt="Home Page" title="Homepage" 
			onmouseover="this.src='buttons/Home2.png'" onmouseout="this.src='buttons/Home1.png'"></a></li>
			<li><a href="products.php"><img src="buttons/Products2.png" alt="Products" title="Our Products" 
			onmouseover="this.src='buttons/Products1.png'" onmouseout="this.src='buttons/Products2.png'"/></a>
			<li><a href="aboutus.php"><img src="buttons/AboutUs1.png" alt="About Us" title="Go to About Us"
			onmouseover="this.src='buttons/AboutUs2.png'" onmouseout="this.src='buttons/AboutUs1.png'"/></a></li>
			<li><a href="contactus.php"><img src="buttons/Contact1.png" alt="Contact Us" title="Go to Contact Us"
			onmouseover="this.src='buttons/Contact2.png'" onmouseout="this.src='buttons/Contact1.png'"/></a></li>
            <li><a href="services.php"><img src="buttons/services1.png" alt="Services" title="Go to Services"
			onmouseover="this.src='buttons/services2.png'" onmouseout="this.src='buttons/services1.png'"/></a></li>
		</ul>
<?php echo $title; ?>

<?php echo $dynamicList;?>

Back to Top <?php include_once("template_footer.php");?>
Sponsor our Newsletter | Privacy Policy | Terms of Service