Hi all, im super stumped here. I have been trying to learn php for some time, and it is terribly confusing to me. I managed to make a product upload script for my shop, but I can’t figure out how to process the product images to main page, and how to send them to product page… So far when I upload the image of product via my backend inventory script it sends the pic to main page HOWEVER it puts it in JPG file extension… (Why does it do this when the file itself is a PNG?) It also sends the image to the product page which is great, but I have 2 distinct images that I need to be placed 1 image is a PNG(will only show a 200x200 preview image) I need it to be placed on main page, and 2nd image which is a JPG,(will be showing a full size of product) I need to be placed on product page. hope you guys can understand all that, I wrote it and I kinda don’t lol Anyway here is the PHP code that I have.
The first block of code is from my backend- add inventory script-
[php]
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 products 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, click here’;
exit();
}
// Add this product into the database now
$sql = mysql_query(“INSERT INTO products (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]
This is the snippet of how I upload my product images.
[php]
I tried making dual image upload options in the form above , I was trying to make one upload to main page, and the other I was trying to MacGyver it to the product page, but couldn’t make it happen.
Main page where the product will be sent after added via backend inventory script
[php]<?php
// Run a select query to get my letest 6 items
// Connect to the MySQL database
include “storescripts/connect_to_mysql.php”;
$dynamicList = “”;
$sql = mysql_query(“SELECT * FROM products ORDER BY date_added DESC LIMIT 6”);
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
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”]));
$dynamicList .= ‘
}
} else {
$dynamicList = “We have no products listed in our store yet”;
}
mysql_close();
?>[/php]
And then I echo out the product list in my html container
[php]<?php echo $dynamicList; ?>[/php]
Hope someone can enlighten me, Seems like im going around in circles on my own.