Jump to content

phpnooblet

New Members
  • Posts

    6
  • Joined

  • Last visited

Everything posted by phpnooblet

  1. So I have the site setup to add products to cart, the products get implemented to cart.php... I just need the customer to have the option to pick style , size, and color. and it show up in the cart.php fields for me to see. I know how to make the html form fields but thats about as far as I go... with much tampering for hours on end to no avail its time to ask the pros...... You can see what I have done, I will leave the site unchanged for now, so whomever would like to take a stab at this can see what i am working with here.... www.shirtstash.com code as follows Option fields - Product Page <form id="form1" name="form1" method="post" action="cart.php"> <input type="hidden" name="pid" id="pid" value="<?php echo $id; ?>" /> <table> <tr> <td> <input type="hidden" name="on0" value="Style"></td> <input type="radio" name="gender" value="Mens">Mens <input type="radio" name="gender" value="Womens">Womens </td> </tr> <tr> <td> <input type="hidden" name="on0" value="Size">Size</td> <td> <select name="os0"> <option value="Small">Small <option value="Medium">Medium <option value="Large">Large <option value="Large">XLarge <option value="Large">XXLarge </select></td> </tr> <tr> <td> <input type="hidden" name="on1" value="Color" maxlength="200">Color</td> <td> <select name="os0"> <option value="Small">White <option value="Medium">Blue <option value="Large">Green </select></td> </tr> <tr> <td> <input type="hidden" name="on0" value="Size">Shipping</td> <td> <select name="os0"> <option value="Small">Standard + Free <option value="Medium">2 Day + $2.00 <option value="Large">Overnight + $5.00 </select></td> </tr> </table> <a href="cart.php"><input type="image" src="/styles/images/paypal.jpg" width="200" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"></a> </form> Cart php ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Section 1 (if user attempts to add something to the cart from the product page) ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if (isset($_POST['pid'])) { $pid = $_POST['pid']; $wasFound = false; $i = 0; // If the cart session variable is not set or cart array is empty if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1) { // RUN IF THE CART IS EMPTY OR NOT SET $_SESSION["cart_array"] = array(0 => array("item_id" => $pid, "quantity" => 1,)); } else { // RUN IF THE CART HAS AT LEAST ONE ITEM IN IT foreach ($_SESSION["cart_array"] as $each_item) { $i++; while (list($key, $value) = each($each_item)) { if ($key == "item_id" && $value == $pid) { // That item is in cart already so let's adjust its quantity using array_splice() array_splice($_SESSION["cart_array"], $i-1, 1, array(array("item_id" => $pid, "quantity" => $each_item['quantity'] + 1))); $wasFound = true; } // close if condition } // close while loop } // close foreach loop if ($wasFound == false) { array_push($_SESSION["cart_array"], array("item_id" => $pid, "quantity" => 1)); } } header("location: cart.php"); exit(); } ?> <?php ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Section 5 (render the cart for the user to view on the page) ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// $cartOutput = ""; $cartTotal = ""; $pp_checkout_btn = ''; $product_id_array = ''; if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1) { $cartOutput = '<div id="carthead"><p>"Your shopping cart is empty"</p></div>'; } else { // Start PayPal Checkout Button $pp_checkout_btn .= '<form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_cart"> <input type="hidden" name="upload" value="1"> <input type="hidden" name="business" value="you@youremail.com">'; // Start the For Each loop $i = 0; foreach ($_SESSION["cart_array"] as $each_item) { $item_id = $each_item['item_id']; $sql = mysql_query("SELECT * FROM products WHERE id='$item_id' LIMIT 1"); while ($row = mysql_fetch_array($sql)) { $product_name = $row["product_name"]; $price = $row["price"]; $details = $row["details"]; } $pricetotal = $price * $each_item['quantity']; $cartTotal = $pricetotal + $cartTotal; setlocale(LC_MONETARY, "en_US"); $pricetotal = money_format("%10.2n", $pricetotal); // Dynamic Checkout Btn Assembly $x = $i + 1; $pp_checkout_btn .= '<input type="hidden" name="item_name_' . $x . '" value="' . $product_name . '"> <input type="hidden" name="amount_' . $x . '" value="' . $price . '"> <input type="hidden" name="quantity_' . $x . '" value="' . $each_item['quantity'] . '"> '; // Create the product array variable $product_id_array .= "$item_id-".$each_item['quantity'].","; // Dynamic table row assembly $cartOutput .= "<tr>"; $cartOutput .= '<td><a href="product.php?id=' . $item_id . '">' . $product_name . '</a><br /><img src="inventory_images/' . $item_id . '.jpg" alt="' . $product_name. '" width="40" height="52" border="1" /></td>'; $cartOutput .= '<td>' . $details . '</td>'; $cartOutput .= '<td>$' . $price . '</td>'; $cartOutput .= '<td><form action="cart.php" method="post"> <input name="quantity" type="text" value="' . $each_item['quantity'] . '" size="1" maxlength="2" /> <input name="adjustBtn' . $item_id . '" type="submit" value="change" /> <input name="item_to_adjust" type="hidden" value="' . $item_id . '" /> </form></td>'; //$cartOutput .= '<td>' . $each_item['quantity'] . '</td>'; $cartOutput .= '<td>' . $pricetotal . '</td>'; $cartOutput .= '<td><form action="cart.php" method="post"><input name="deleteBtn' . $item_id . '" type="submit" value="X" /><input name="index_to_remove" type="hidden" value="' . $i . '" /></form></td>'; $cartOutput .= '</tr>'; $i++; } setlocale(LC_MONETARY, "en_US"); $cartTotal = money_format("%10.2n", $cartTotal); $cartTotal = "<div style='font-size:18px; margin-top:12px;' align='right'>Cart Total : ".$cartTotal." USD</div>"; // Finish the Paypal Checkout Btn $pp_checkout_btn .= '<input type="hidden" name="custom" value="' . $product_id_array . '"> <input type="hidden" name="notify_url" value="https://www.yoursite.com/storescripts/my_ipn.php"> <input type="hidden" name="return" value="https://www.yoursite.com/checkout_complete.php"> <input type="hidden" name="rm" value="2"> <input type="hidden" name="cbt" value="Return to The Store"> <input type="hidden" name="cancel_return" value="https://www.yoursite.com/paypal_cancel.php"> <input type="hidden" name="lc" value="US"> <input type="hidden" name="currency_code" value="USD"> <input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but01.gif" name="submit" alt="Make payments with PayPal - its fast, free and secure!"> </form>'; } ?> from the above I think I should manipulate this $_SESSION["cart_array"] = array(0 => array("item_id" => $pid, "quantity" => 1,)); to this BUT I do not know how to implement the variables / arrays. $_SESSION["cart_array"] = array(0 => array("item_id" => $pid, "quantity" => 1,"size"=>$size,"color"=>$color,"style"=>$style)); Cart html <table width="100%" border="1" cellspacing="0" cellpadding="6"> <tr> <td width="18%" bgcolor="orange"><strong>Product</strong></td> <td width="37%" bgcolor="orange"><strong>Product Description</strong></td> <td width="10%" bgcolor="orange"><strong>Unit Price</strong></td> <td width="9%" bgcolor="orange"><strong>Quantity</strong></td> <td width="9%" bgcolor="orange"><strong>Style</strong></td> <td width="9%" bgcolor="orange"><strong>Size</strong></td> <td width="9%" bgcolor="orange"><strong>Color</strong></td> <td width="9%" bgcolor="orange"><strong>Total</strong></td> <td width="9%" bgcolor="orange"><strong>Remove</strong></td> </tr> <?php echo $cartOutput; ?> <!-- <tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> --> </table> Thats all the code I know to post... If am missing a block pls tell me and I will grab it.
  2. When I uploaded the images they were getting sent to both index.php and product.php?id= I only wanted the small display image on home page, where I would have countless others and when the user/customer clicks that image/images it take them to product page where I would have a totally different image there even a gallery maybe.... however using your tips I "MacGyver'd" it to show the image change..(i now upload the jpg, but I have to manually insert the png into image folder and name it the id of other image but attach .png and it works that way) still not exactly what I wanted but It will do the trick for now.... Thanks btw if anyone know how to manipulate the backend upload script I posted so I can upload both images , and not have to manually insert the 2nd one via ftp.. would be so cool...
  3. how would I put that in? this is the code that gets executed on index.php $dynamicList = ""; $dynamicList .= '<div class="ts"><a href="product.php?id=' . $id . '"><img src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="200" height="205" /><figcaption>'.$product_name.'</figcaption></a></div>'; <div id="container"> <?php echo $dynamicList; ?> <---- thats the uploaded 200x205 sample image/images </div> btw the small image on main page shows the shirt art.. on product page the image will be different showing the art on the shirt.
  4. you can check out my rough draft site to see what i mean.. www.shirtstash.com the sample image I uploaded via inventory script i made.. is originally docbrown.png then somehow gets labeled 32.jpg.... I guess all thats fine I just don't need it to show up on the product page.. I need it to link there but have another image there instead. I was thinking of making an extra field in my image upload script so I would have 2 image upload options 1 would be sent to index.php(sample image) and full sized display image be sent to the product page..but I have no Idea of how to make it direct to product.php?id= instead of index.php if that makes any sense
  5. actually I have changed that to $pid.png before I posted this and it still outputs a .jpg file
  6. 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- 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, <a href="inventory_list.php">click here</a>'; 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(); } ?> This is the snippet of how I upload my product images. <tr> <td align="right">Product Image</td> <td><label> <input type="file" name="fileField" id="fileField" /> </label></td> </tr> <tr> <td> </td> <td><label> <input type="submit" name="button" id="button" value="Add This Item Now" /> </label></td> </tr> 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 // 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 .= '<div class="ts"><a href="product.php?id=' . $id . '"><img src="inventory_images/' . $id . '.png" alt="' . $product_name . '" width="200" height="205" /><figcaption>'.$product_name.'</figcaption></a></div> '; } } else { $dynamicList = "We have no products listed in our store yet"; } mysql_close(); ?> And then I echo out the product list in my html container <?php echo $dynamicList; ?> Hope someone can enlighten me. Seems like im going around in circles on my own.
×
×
  • 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.