Jump to content

MsKazza

Members
  • Content Count

    88
  • Joined

  • Last visited

Community Reputation

0 Neutral

About MsKazza

  • Rank
    Regular Member
  • Birthday 08/05/1978

Profile Information

  • Gender
    Female
  • Location
    Ireland
  1. Ok well it was great for all of five minutes till i realized it is only adding one item, when i try to add another it just replaces the first item, i'm guessing there should be a counter being incremented for each item a new array. case "add": if(!empty($_POST["quantity"])) { $productByCode = $db_handle->runQuery("SELECT * FROM products WHERE product_code='" . $_GET["product_code"] . "'"); $itemArray = array($productByCode[0]["product_code"]=>array('product_name'=>$productByCode[0]["product_name"], 'product_code'=>$productByCode[0]["product_code"], 'quantity'=>$_POST["quantity"], 'price'=>$productByCode[0]["price"], 'image'=>$productByCode[0]["img1"])); if(!empty($_SESSION["cart_item"])) { if(in_array($productByCode[0]["product_code"],array_keys($_SESSION["cart_item"]))) { foreach($_SESSION["cart_item"] as $k => $v) { if($productByCode[0]["product_code"] == $k) { if(empty($_SESSION["cart_item"][$k]["quantity"])) { $_SESSION["cart_item"][$k]["quantity"] = 0; } $_SESSION["cart_item"][$k]["quantity"] += $_POST["quantity"]; } } } else { $_SESSION["cart_item"] = array_merge($_SESSION["cart_item"],$itemArray); } } else { $_SESSION["cart_item"] = $itemArray; } } for some reason that i can't figure out yet the array_merge is not merging the two arrays. I think the fault lies in this line $_SESSION["cart_item"] = array_merge($_SESSION["cart_item"],$itemArray); but not 100% sure, should it be adding(appending) using a + symbol?
  2. ohhhhhhhh, that second one should be an ampersand? & Edit: Yep tried and it should have been an &, thank you guys, felt like a prat when i finally saw it. whole thing works like a charm now
  3. i'm really sorry i don't get it, if you mean that one is called schoolname and the other school_page i'm aware, school_page is the shortened version of the schoolname which i use for passing variables etc rather than the long name. i tried moving the schoolname=school_page to the end of the line and it sort of worked, added a quantity of one but no other information was passed. and the array results now look like : array(1) { ["cart_item"]=> array(1) { [""]=> array(5) { ["product_name"]=> NULL ["product_code"]=> NULL ["quantity"]=> int(7) ["price"]=> NULL ["image"]=> NULL } } } array(2) { ["size"]=> string(1) "S" ["quantity"]=> string(1) "1" }
  4. i thought it might be the quotes around product_code not (i think the term is ) escaping properly. tried it still no joy. <form action="student_order.php?schoolname=<?php echo $school_page; ?>?action=add&product_code=<?php echo $product_array[$key]['product_code']; ?>" method="post"> The url passes the product code http://localhost/leavers/student_order.php?schoolname=ravenswell?action=add&product_code=JH004 and the post data shows its passing the size and quantity array(2) { ["size"]=> string(1) "L" ["quantity"]=> string(1) "1" } The cart still shows as empty, I tried to pear my cart down and just put in basic information, without the need for the schoolname etc and it works great, so maybe the add cart function is not working because of the schoolpage, either that or i'm totally missing something.
  5. thanks for your reply, i'll keep that in mind while implementing it, for now only intend on using it on one page, but i guess future proofing site couldn't hurt.
  6. Hey again, Still on the same project but now doing the cart page. I've been bringing my skills up to date a lot doing this project, however, having said that I now can't figure out why my cart is not adding the items to the cart, i've checked the post data and the quantity is set to 1. Would really appreciate someone having a look at it and hopefully can see what i'm missing. you can see what it should look like (well so far lol) at here in my sandbox site. thanks again. (p.s. The parts are all over the place on the page, so thought better put whole page, sorry if shouldn't have done that) <?php // Initialize the session session_start(); // Include config file require_once "dbcontroller.php"; $db_handle = new DBController(); if(!empty($_GET["action"])) { switch($_GET["action"]) { case "add": if(!empty($_POST["quantity"])) { $productByCode = $db_handle->runQuery("SELECT * FROM products WHERE product_code='" . $_GET["product_code"] . "'"); $itemArray = array($productByCode[0]["product_code"]=>array('product_name'=>$productByCode[0]["product_name"], 'product_code'=>$productByCode[0]["product_code"], 'quantity'=>$_POST["quantity"], 'price'=>$productByCode[0]["price"], 'image'=>$productByCode[0]["img1"])); if(!empty($_SESSION["cart_item"])) { if(in_array($productByCode[0]["product_code"],array_keys($_SESSION["cart_item"]))) { foreach($_SESSION["cart_item"] as $k => $v) { if($productByCode[0]["product_code"] == $k) { if(empty($_SESSION["cart_item"][$k]["quantity"])) { $_SESSION["cart_item"][$k]["quantity"] = 0; } $_SESSION["cart_item"][$k]["quantity"] += $_POST["quantity"]; } } } else { $_SESSION["cart_item"] = array_merge($_SESSION["cart_item"],$itemArray); } } else { $_SESSION["cart_item"] = $itemArray; } } break; case "remove": if(!empty($_SESSION["cart_item"])) { foreach($_SESSION["cart_item"] as $k => $v) { if($_GET["product_code"] == $k) unset($_SESSION["cart_item"][$k]); if(empty($_SESSION["cart_item"])) unset($_SESSION["cart_item"]); } } break; case "empty": unset($_SESSION["cart_item"]); break; } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>LeaversHoodies.ie</title> <!-- Bootstrap --> <link href="css/bootstrap-4.4.1.css" rel="stylesheet"> <link href="css/accordian.css" rel="stylesheet"> </head> <body> <?php include 'header_student.php'; ?> <br /> <?php $school_page = "ravenswell"; $sql = "SELECT * FROM schools WHERE school_page = '$school_page'"; if($result = mysqli_query($conn, $sql)) while($row = mysqli_fetch_array($result)) { ?> <h3 class="text-center">Student Ordering Page For</h3> <h2 class="text-center" style="text-transform:uppercase;"><?php echo $row['school_name']; ?></h2> <hr style="width: 50%; text-align:center; border: 2px solid #00aeef; border-radius: 5px; margin: 0 auto;"> <br /> <div class="container"> <div class="row"> <div class="col"> <?php $path = "images/schools/"; $file = $row["logo"]; if(!empty($row['logo'])) { echo '<img src="'.$path.$file.'" style="width:95%; height:auto; margin-top:-130px;"><br /><br />'; } else { echo '<img src="images/schools/140x140.gif" style="width:95%; height:auto; margin-top:-130px;"><br /><br />'; } ?></div> <div class="col-6"> <h5>These are the garments your school has choosen :</h5><br /> <?php $school_id = $row["school_id"]; } var_dump($_SESSION); var_dump($_POST); $product_array = $db_handle->runQuery("SELECT * FROM choices INNER JOIN products USING (product_code) INNER JOIN colours USING (colour_id) WHERE school_id = '$school_id'"); if (!empty($product_array)) { foreach($product_array as $key=>$value){ ?> <div class="container"> <div class="row"> <div class="col-5" style="text-align:left;"> <img src="images/products/<?php echo $product_array[$key]["img1"]; ?>" alt="<?php echo $product_array[$key]["product_code"]; ?>" style="position:relative; top:0; width:200px; display:block;"> </div> <div class="col-7"> <h5><?php echo $product_array[$key]["product_name"]; ?></h5><p> in <?php echo $product_array[$key]["colour_name"]; ?></p> <p style="font-size:12px;"><?php echo $product_array[$key]["description"]; ?></p> <?php $comment = $product_array[$key]["comment"]; if (empty($comment)) { echo ""; } else { ?> <p style="font-size:12px;"><b>A note from your teacher:</b> <br /> <?php echo $product_array[$key]["comment"]; ?></p> <?php }; ?> <form action="student_order.php?schoolname=<?php echo $school_page; ?>?action=add&product_code=<?php echo $product_array[$key]["product_code"]; ?>" method="post"> <?php $product = $product_array[$key]["product_code"]; ?> Please select your size : <select id="size" name="size"> <?php $sql1 = "SELECT DISTINCT * FROM sizes WHERE product_code = '$product'"; if($result1 = mysqli_query($conn, $sql1)) while($row3 = mysqli_fetch_array($result1)){ echo "<option value='" . $row3['size'] . "'>" . $row3['size'] . "</option>"; } else { echo "nothing to see here"; } ?> </select> <br /><br /> <div class="number">How many do you want: <input type="number" style="font-size:12px;" id="quantity" name="quantity" value="1" min="1" max="5"><br /> Price : <?php echo "€".$product_array[$key]["price"]; ?> </div> <input type="hidden" id="product_code" value="<?php echo $product; ?>"><br /> <input type="submit" style="font-size:12px;" value="Add to Order" class="btnAddAction"> </form> </div> </div> <br /><hr style="width: 90%; text-align:center; border: 1px solid #00aeef; border-radius: 5px; margin: 0 auto;"><br /> </div> <?php } } else { echo "No Schools by that name registered."; } ?> </div> <div class="col-3"> <div style="border: 1px solid #d3d3d3; padding: 10px; border-radius: 5px; margin-top:30px;"> Your Order: </div> </div> </div> <div class="txt-heading">Shopping Cart</div> <a id="btnEmpty" href="student_order.php?schoolname=<?php echo $school_page; ?>?action=empty">Empty Cart</a> <?php if(isset($_SESSION["cart_item"])){ $total_quantity = 0; $total_price = 0; ?> <table class="tbl-cart" cellpadding="10" cellspacing="1"> <tbody> <tr> <th style="text-align:left;">Name</th> <th style="text-align:left;">Code</th> <th style="text-align:right;" width="5%">Quantity</th> <th style="text-align:right;" width="10%">Unit Price</th> <th style="text-align:right;" width="10%">Price</th> <th style="text-align:center;" width="5%">Remove</th> </tr> <?php foreach ($_SESSION["cart_item"] as $item){ $item_price = $item["quantity"]*$item["price"]; ?> <tr> <td><img src="images/products/<?php echo $item["img1"]; ?>" class="cart-item-image" /><?php echo $item["product_name"]; ?></td> <td><?php echo $item["product_code"]; ?></td> <td style="text-align:right;"><?php echo $item["quantity"]; ?></td> <td style="text-align:right;"><?php echo "$ ".$item["price"]; ?></td> <td style="text-align:right;"><?php echo "$ ". number_format($item_price,2); ?></td> <td style="text-align:center;"><a href="student_order.php?schoolname=<?php echo $school_page; ?>?action=remove&product_code=<?php echo $item["product_code"]; ?>" class="btnRemoveAction"><img src="icon-delete.png" alt="Remove Item" /></a></td> </tr> <?php $total_quantity += $item["quantity"]; $total_price += ($item["price"]*$item["quantity"]); } ?> <tr> <td colspan="2" align="right">Total:</td> <td align="right"><?php echo $total_quantity; ?></td> <td align="right" colspan="2"><strong><?php echo "$ ".number_format($total_price, 2); ?></strong></td> <td></td> </tr> </tbody> </table> <?php } else { ?> <div class="no-records">Your Cart is Empty</div> <?php } ?> </div> </div> <br /><br /> <?php include 'footer_student.php'; ?> <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> <script src="js/jquery-3.4.1.min.js"></script> <!-- Include all compiled plugins (below), or include individual files as needed --> <script src="js/popper.min.js"></script> <script src="js/bootstrap-4.4.1.js"></script> </body> </html>
  7. thanks very much for that, i'll look into it now. Am only going to be using it for the one page, and not using wordpress just that where i thought i'd seen something like it. thanks again.
  8. Hi Not even sure if this is possible, but well here goes: We have a wholesale site where companies, organisations, clubs etc can buy products. We are setting it up so that these organisations can pick their items then our system will set up a webshop for them, they can then send the link to their employees, members to order the items that the company has chosen ahead of time. our site would be http://www.ourcompanyname.com/productpage.php?companyName=ourClient we would like if poss : http://www.ourcompanyname.com/ClientOrganisationName(either with or without the PHP extension). ClientOrganisationName would be taken from their record in mysql. If this is possible could someone please just tell me what i need to look up. I think wordpress has something similar which is prob where i thought about using on our site. thanks very much, MsKazza.
  9. thank you soo much, when i see the code i can follow along and know what your doing, however doing it myself from scratch is another matter all together. I really appreciate your help.
  10. thank you for your reply. once i had the original tab gallery working i looked up how to preload the first image, someone else had asked that and said this is what had worked for them so thought would give it try. obv didn't work and thought it was me. i really appreciate you taking the time to help. I've looked up about getElementsByClassName, however i'm still not sure how to call the function from the div where the main image should appear. Thought it might be something like <img id="expandedImg" style="height:450px;" onload="initMainImg();"> but well no obviously i'm wrong. I only know basic javascript, so all help is really appreciated.
  11. I'm sorry I don't want to come across as rude, how is that comment in any way helpful? Why even bother posting such a thing? Looking at any of this for another few hours isn't gonna help me understand what went wrong. I asked for help, not someone to tell me to just stare at the code again. You think I haven't tried lots of different fixes before posting here? Can anyone please offer any real help to point me in the right direction to fix whatever i've obviously done wrong. Apparently there is something wrong with my variables, can anyone help me figure out what please. Thanks for any help guys.
  12. Hi followed the tutorial from w3 on the image tab gallery (https://www.w3schools.com/howto/howto_js_tab_img_gallery.asp). On their own page the first image preloads when you refresh/enter page. But in their tutorial code it doesn't. I've tried writing some code to figure it out but so far no luck. Was hoping someone could point me in the right direction. ATM the image preloads in the correct place, however now none of my other images will show in big when i click them. My code below. Thanks so much for any help. MsKazza <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>College Hoodie - leavershoodies.ie</title> <!-- Bootstrap --> <link href="css/bootstrap-4.4.1.css" rel="stylesheet"> <!-- jQuery 1.8 or later, 33 KB --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <style> * { box-sizing: border-box; } body { margin: 0; font-family: 'gothambook'; } /* The grid: Four equal columns that floats next to each other */ .column_images { float: left; width: 75px; padding: 10px; } /* Style the images inside the grid */ .column_images img { opacity: 0.8; cursor: pointer; margin-left:17px; } .column_images img:hover { opacity: 1; margin-left:17px; } /* Clear floats after the columns */ .row_images:after { content: ""; display: table; clear: both; } /* The expanding image container */ .container2 { position: relative; display: block; width:350px; text-align:center; /* background-color: #5e5e5e; */ } /* Expanding image text */ #imgtext { position: absolute; bottom: 15px; left: 40%; color: #5e5e5e; font-size: 20px; } /* Closable button inside the expanded image */ .closebtn { position: absolute; top: 10px; right: 15px; color: white; font-size: 35px; cursor: pointer; } </style> </head> <body onload="myFunction()"> <?php include 'header.php'; ?> <?php $product_id = $_GET['recordID']; $sql = "SELECT * FROM products WHERE product_code = '$product_id'"; if($result = mysqli_query($conn, $sql)) while($row = mysqli_fetch_array($result)) { ?> <div class="container" style="margin-top:10px;"> <div class="row"> <div class="col-4"> <div class="container2"> <span onclick="this.parentElement.style.display='none'" class="closebtn" ></span> <img id="expandedImg" style="height:450px"><br /><br /> <div id="imgtext"></div> </div> <div class="row_images"> <div class="column_images"> <img src="images/products/<?php echo $row['img1']; ?>" id="thumbimg" alt="" style="height:100px" onclick="myFunction(this);"> </div> <div class="column_images"> <img src="images/products/<?php echo $row['img2']; ?>" alt="" style="height:100px" onclick="myFunction(this);"> </div> <div class="column_images"> <img src="images/products/<?php echo $row['img3']; ?>" alt="" style="height:100px" onclick="myFunction(this);"> </div> <div class="column_images"> <img src="images/products/<?php echo $row['img4']; ?>" alt="" style="height:100px" onclick="myFunction(this);"> </div> </div> </div> <!-- end of left 5 column --> <div class="col-8"> <h1 class="text-center"><?php echo $row['product_name']; ?></h1> <br /> <div class="container-fluid"> <div class="row"> <div class="col-3"><h5>Description</h></div> <div class="col"> <?php echo $row['description']; ?> </div> </div> <!-- /row --><br /> <div class="row"> <div class="col-3"><h5>Specification</h></div> <div class="col"> <?php echo $row['specification']; ?> </div> </div> <!-- /row --><br /> <div class="row"> <div class="col-3"><h5>Available Sizes</h></div> <div class="col"> XS - S - M - L - XL - XXL - 3XL </div> </div> <!-- /row --> </div> <!-- desc container --> <br /><br /> <div class="container"> <div class="row"> <div class="col"> <?php $sql = "SELECT * FROM colours WHERE product_id = '$product_id'"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo ' <div style="float:left; width:55px; text-align:center;"> <label class="container"> <img src="images/products/pakshots/'.$row["filename"].'" alt="'.$row["colour_name"].'" style="width:50px" onclick="myFunction(this);"> <br /><input type="radio" checked="checked" name="colour"> <span class="checkmark"></span> </label> </div> '; } } else { echo "0 results"; } $conn->close(); ?> </div> </div> </div> </div> </div> <!-- end of main content column --> </div> <!-- end of main content row --> </div> <!-- end of main container --> <hr> <div class="container"> <div class="row"> <div class="text-center col-md-6 col-12"> <h3>More Information</h3> <p>If your not quite sure yet and would like to discuss further please either call us, request a call back, or get a quote on this product.</p> <a class="btn btn-success btn-lg" href="#" role="button">GET QUOTE</a> <a class="btn btn-danger btn-lg" href="#" role="button">REQUEST CALL BACK</a> </div> <div class="text-center col-md-6 col-12"> <h3>Loving it? Lets go!</h3> <p>If you've made your choice and this is the top for you and yours, please select the colour you would like and click 'Choose this top'.</p> <a class="btn btn-primary btn-lg" href="#" role="button">REGISTER / LOGIN</a> <a class="btn btn-info btn-lg" href="#" role="button">CHOOSE THIS TOP</a> </div> </div> </div> <br /><br /> <?php } ?> <?php include 'footer.php'; ?> <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> <script src="js/jquery-3.4.1.min.js"></script> <!-- Include all compiled plugins (below), or include individual files as needed --> <script src="js/popper.min.js"></script> <script src="js/bootstrap-4.4.1.js"></script> <script> function myFunction(imgs) { var expandImg = document.getElementById("expandedImg"); var imgText = document.getElementById("imgtext"); var imgs = document.getElementById("thumbimg");//thumbimg is the id of thumb image which you might want to add expandImg.src = imgs.src; imgText.innerHTML = imgs.alt; expandImg.parentElement.style.display = "block"; } </script> </body> </html>
  13. Hi, i'm recently had to add a new value to our product database called supplier_id, which gets called from the supplier table. Now when i'm trying to add a new product, it looks up the supplier name, but i'm not sure where/how to add the supplier_id so that it gets past to the POST, if someone could help me would much appreciate it. Please see attached file. Thanks, MsKazza <?php include('header.php'); ?> <style> table { width: 600px; } th { height: 50px; } td { height: 30px; vertical-align: middle; } </style> </head> <body> <?php include('navbar.php'); if (isset($_POST['submit'])) { $product_code = $_POST['product_code']; $product_name = $_POST['product_name']; $supplier_id = $_POST['supplier_id']; $supplier = $_POST['supplier']; $category = $_POST['category']; $sub_category = $_POST['sub_category']; $category2 = $_POST['category2']; $sub_category2 = $_POST['sub_category2']; $sql = "SELECT * FROM sub_categories WHERE id = '$sub_category'"; $subcat_result = $con->query($sql); while ($row=mysqli_fetch_array($subcat_result)) { $subcat_name = $row['subcat_name']; } $sub_category1 = preg_replace('/[^a-zA-Z0-9_.]/', '-', $subcat_name); $product_name1 = preg_replace('/[^a-zA-Z0-9_.]/', '-', $product_name); $slug = $sub_category1 . "/" . $product_name1; $slug = strtolower($slug); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } // Perform queries mysqli_query($con,"INSERT INTO products (product_code, slug, supplier_id, supplier, category, sub_category, category2, sub_category2,product_name) VALUES ('$product_code', '$slug', '$supplier_id', '$supplier', '$category', '$sub_category', '$category2', '$sub_category2', '$product_name')"); // Perform queries mysqli_query($con,"INSERT INTO images (product_code) VALUES ('$product_code')"); ?> <script> location.replace("products.php"); </script> <? mysqli_close($con); } else { ?> <script language="javascript" type="text/javascript"> function getXMLHTTP() { //fuction to return the xml http object var xmlhttp=false; try{ xmlhttp=new XMLHttpRequest(); } catch(e) { try{ xmlhttp= new ActiveXObject("Microsoft.XMLHTTP"); } catch(e){ try{ xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e1){ xmlhttp=false; } } } return xmlhttp; } function getSubcat(categoryId) { var strURL="findsubcat.php?category="+categoryId; var req = getXMLHTTP(); if (req) { req.onreadystatechange = function() { if (req.readyState == 4) { // only if "OK" if (req.status == 200) { document.getElementById('subcatdiv').innerHTML=req.responseText; } else { alert("Problem while using XMLHTTP:\n" + req.statusText); } } } req.open("GET", strURL, true); req.send(null); } } </script> <form method="post" action="" name="addproduct"> <?php $sql = "SELECT * FROM categories ORDER BY cat_name ASC"; $result = $con->query($sql); ?> <div class="container-fluid text-center"> <div class="row content"> <div class="col-sm-12 text-left"> <br /> <h1>Add New Product</h1> <br /> <table> <tr><td>Product Code : </td><td><input type="text" name="product_code" ></td></tr> <tr><td>Product Name : </td><td><input type="text" name="product_name" size="50px"></td></tr> <tr><td><div class="form-group"> <label for="name">Supplier</label><a href="#" style="font-size:12px"> (Edit)</a></td> <td><label class="input-group p-custom-arrow"> <select id="supplier" name="supplier" value="<?php echo $product['supplier']; ?>" class="form-control"> <option class="p-select-default" value="">Select Supplier</option> <?php $sql=mysqli_query($con,"select * from supplier ORDER BY supplier_name ASC"); while($row=mysqli_fetch_array($sql)) { ?> <option value="<?php echo $row['folder']; ?>" <?php if ($product['supplier'] == $row['folder']) echo ' selected="selected"' ?>><?php echo $row['supplier_name']; ?></option> <?php } ?> </select> </label> </div><br /></td></tr><!-- End: form group --> <tr><td style="width:150px;"> Category : </span></td><td><select name="category" onChange="getSubcat(this.value)"> <option value="">Select Category</option> <?php while ($row=mysqli_fetch_array($result)) { ?> <option value=<?php echo $row['id']?>><?php echo $row['cat_name']?></option> <?php } ?> </select> </td></tr> <tr><td style="width:150px;">Sub Category : </span></td><td><div id="subcatdiv"><select name="sub_category" > <option>Select Subcategory</option> </select></div><br /> </td></tr> </table><br /> <input type="submit" value="submit" name="submit"> </form> </div> </div> </div> </div> <?php } ?> <?php include('footer.php'); ?> </body> </html> addproduct.php
  14. Hi there, I was trying to do a live table edit for our site. Everything seemed to be going ok, till i realised that its not actually updating the database, there are no error messages, you have to refresh the page to see it hasn't worked. I'm at a loss as to why was hoping someone might be able to point me in the right direction. thanks, MsKazza tableedit.php table_edit_ajax.php
  15. Can anyone please help me with this? thanks MsKazza
×
×
  • 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.