Jump to content

Samza

Members
  • Posts

    26
  • Joined

  • Last visited

Contact Methods

  • Website URL
    http://sambruton.co.uk

Profile Information

  • Gender
    Not Telling
  • Interests
    Web Development : PHP, HTML, CSS, JavaScript, MySQL.

Samza's Achievements

Newbie

Newbie (1/5)

1

Reputation

  1. Hey guys! I am trying to achieve the following functionality; Use javascript to display page content that is stored on one page by showing the requested content through the navigation, i.e. clicking the Home link, and making the previous page content invisible. I have been playing around with altering the CSS styling off the div's. I have 3 div's each name; Home, Portfolio and Enquire. Here is the CSS for them; #home { display: block; } #portfolio { display: none; } #enquire { display: none; } So from this the home div is the first that is seen when the page loads. Now using the navigation I have I am calling a function; <nav class="row"> <ul> <li class="above-border"> </li> <li class="nav-smallfont">about</li> <li><a href="javascript:toggle_visibility('portfolio');" alt="Portfolio" target="_self">PORTFOLIO</a></li> <li class="above-border"> </li> <li class="nav-smallfont">back</li> <li><a href="javascript:toggle_visibility('home');" alt="Homepage" target="_self">HOME</a></li> <li class="above-border"> </li> <li class="nav-smallfont">furniture</li> <li><a href="#" onclick="toggle_visibility('enquire');" alt="Enquire" target="_self">ENQUIRE</a></li> <li class="above-border"> </li> </ul> </nav> I was playing around with the difference between onclick and javascript: - I didnt really see any major difference. Now my Javascript is this; <script type="text/javascript"> function toggle_visibility(id) { var e = document.getElementById(id); if(e.style.display == 'block'){ e.style.display = 'none'; } else{ e.style.display = 'block'; } } </script> Now whenever I click on the home navigation it will show/hide the content and when I click on say, the portfolio link it will show this content as well as the home. Im pretty sure you understand what I am hoping to achieve; A navigation style functionality so that when the portfolio link is click, it hides the other content and show only that and visa versa for the other links. Thanks for your help! Sam
  2. Thanks mac_gyver, I have resolved this issue I appreciate your help!
  3. Thanks for this help, I was following a tutorial previously but it clearly was a bit messed up and didnt need to be that completed for my cart. Anyway here's what I've got; function Paypal_items() { //Get the items to submit for paypal $cart = new ShoppingCart; $cart_id = $cart -> get_cart_id(); // run 1 query to get the customers cart details // create a loop over the cart rows to output the fields $num = 0; $sql = mysql_query("SELECT * FROM shopping_cart WHERE cart_identifier='".mysql_real_escape_string($cart_id)."'"); $result = mysql_fetch_array($sql,0); $count = mysql_num_rows($sql); $i = 0; while($i < $count) { $num++; $i = $i+1; echo "<input type=\"hidden\" name=\"item_number_".$num."\" value=\"".$result[product_id]."\" />"; echo "<input type=\"hidden\" name=\"item_name_".$num."\" value=\"".$result[product_title]."\" />"; echo "<input type=\"hidden\" name=\"amount_".$num."\" value=\"".$result[product_price]."\" />"; } } However, one problem I am having this that if there is more than 1 item in the cart, it is repeating the same data from the 1st cart record rather than for each cart item
  4. Or if anyone knows any good websites that help teach about arrays in a practical way that would be great help
  5. Hey guys, I have created a shopping cart system and I am now up to the point of building the checkout script to allow the customer to checkout using paypal. I have the bqasic paypal script form however I now need to create an array which pulls the data out of the customers shopping cart (which is stored in a DB) and for each product, output in the form of a hidden input form with the fields; item_number_x, item_id_x, item_price_x, item_quantity_x. Where X is the value of each product in the shopping cart. I am really suck on where to start and could do with some advice. This is the code that I originally tried however Im not have any luck as I am fairly new to using arrays; function Paypal_items() { //Get the items to submit for paypal $cart = new ShoppingCart; $cart_id = $cart -> get_cart_id(); $num = 0; $cart_sql = mysql_query("SELECT product_id, product_title, product_price FROM shopping_cart WHERE cart_identifier='".mysql_real_escape_string($cart_id)."'"); $cart_result = mysql_fetch_assoc($cart_sql); foreach ($cart_result as $name => $value) { if ($value != 0) { if($name){ $product_id = $name; echo "<br />name: " . $product_id . " : value". $value; } $sql = mysql_query("SELECT product_id, product_title, product_price FROM shopping_cart WHERE cart_identifier='$cart_id'"); while ($sql_result = mysql_fetch_assoc($sql)) { $num++; echo $num; echo "<input type=\"hidden\" name=\"item_number_\"".$num." value=\"".$product_id."\""; } } else { echo "!= is false<br />"; } } } Thanks!
  6. Thanks very much for your help Barand. I will never nest mysql querys again! Muchas gracis!
  7. Thanks for your help guys, I tried count (*) but it was the space between count and (*) that was the main problem! sorted now However this is an error im having on this line mysql_result(mysql_query("SELECT SUM(product_qty * product_price) AS subtotal WHERE cart_identifier='". mysql_escape_string($cart_id) ."'"), 0); error message
  8. Hi, I am having a problem with fixing this mysql error; This is the line 8 it is refering to; $num_items = mysql_result(mysql_query("SELECT COUNT * as items FROM shopping_cart WHERE cart_identifier=". mysql_escape_string($cart_id) .""),0); and this is what it looks like when I echo it out; I can seem to see the problem but hopefuly someone here can see through this. Thanks!
  9. Oh yes ! Got it finally! Thanks so much ! Finally I can move on with my life
  10. I echoed it out and I can't see what is wrong, everything seems to be perfect
  11. Hey, I am getting this error; and the mysql_query is; $sql = mysql_query("INSERT INTO shopping_cart (cart_identifier, product_id, product_title, product_qty, product_price, sdate) VALUES ('". mysql_real_escape_string($_SESSION['cid']) . "', '$product_id', '{$products['product_title']}', '$product_qty', '{$products[product_price]}', '$sdate'") or die (mysql_error()); I have exhausted every optional my knowledge can devise! Thanks for your help, Sam
  12. I have also checked to see the data in the variables below; $sql_get_products echo's nothing and $sql_check echo's 'Resource id #11'.
  13. Hi cyberRobot, Yes I echo out the variables to check if cart.php was receiving the data which it is. I now believe it has something to do with this line in cart.php - the output is dropping into the if(!$add2cart) which clear thinks it is FALSE. $add2cart = $cart->cart_add($_REQUEST['product_id'], $_REQUEST['product_qty']); This means the underlying issue is in the function named cart_add in clsShoppingCart.php file however I am unsure on how I can test this part as it gets quiet complicated from line 24. while($row = mysql_fetch_array($sql_check)){ $products = mysql_fetch_assoc($sql_get_product); if(($product_qty + $products[product_qty]) > $products[product_qty]){ $new_qty = $products[product_qty]; } else { $new_qty = ($product_qty + $row[product_qty]); } $sql = mysql_query("UPDATE shopping_cart SET product_qty='$new_qty', date = now() WHERE id='{$row['id']}'"); $skip = TRUE; } if(!$skip){ $products = mysql_fetch_assoc($sql_get_product); if($products[product_qty] < $product_qty){ $product_qty = $products[product_qty]; } if($product_qty > 0){ $sql = mysql_query("INSERT INTO shopping_cart (cart_identifier, product_id, product_title, product_qty, product_price, date) VALUES ('{$_SESSION['cid']}', '$product_id', '{$products['product_title']}', '$product_qty','{$products['product_price']}', now())"); } else { $sql = FALSE; } } if(!$sql){ return FALSE; } else { return TRUE; } }//end cart_add()
  14. Hey guys and girls, I am currently following a book to create a PHP shopping cart and I am having trouble passing the data from a form to my cart script that add's the product to the cart. This is the products.php file which contains the form & action which is posting the data from the input forms 'product_qty', 'product_id', and 'req=add': <table width="100%" border="0" cellspacing="0" cellpadding="4"> <tr> <td colspan="2"> <a href="/newagedclothing/content/products.php?req=view&product_id=<?php echo $product_id; ?>"> <?php echo $product_title; ?> </a> </td> </tr> <tr> <td width="16%" align="left" valign="top"> <strong>Description:</strong></td> <td width="84%"> <?php echo $caption; ?> </td> </tr> <tr> <td align="left" valign="top"><strong>Price:</strong></td> <td> <?php echo $product_price; ?> </td><?php echo $product_id; ?> </tr> <tr> <td> </td> <td><form method="post" action="index.php?content=cart"> <strong>Add To Cart</strong> <input name="product_qty" type="text" value="1" size="2" /> <input type="hidden" name="req" value="add" /> <input type="hidden" name="product_id" value="<?php echo $product_id; ?>" /> <input type="submit" name="Submit" value="Go!" /> </form> </td> </tr> </table> <hr size="1"> This is the cart.php file: <?php $cart = &new ShoppingCart; $cart_id = $cart->get_cart_id(); switch($_REQUEST['req']){ case "add": $add2cart = $cart->cart_add($_REQUEST['product_id'], $_REQUEST['product_qty']); if(!$add2cart){ echo "<center>The product could not be ". "to your shopping cart. You may ". "have entered an invalid quantity. </center>" . $add2cart; } else { echo "<center>Item added to your shopping cart!<br />". "<a href=\"/cart.php\">View ". "your cart</a></center>"; } break; case "update": while(list($product_id, $qty) = each($_POST[qty])){ $sql = mysql_query("SELECT * FROM shopping_products WHERE product_id='$product_id'"); $row = mysql_fetch_assoc($sql); if($qty == 0){ mysql_query("DELETE FROM shopping_cart WHERE cart_identifier='$cart_id' AND product_id='$product_id'"); } if($qty > $row[product_qty]){ mysql_query("UPDATE shopping_cart SET product_qty='{$row[product_qty]}' WHERE cart_identifier='$cart_id' AND product_id='$product_id'"); $error = TRUE; $products[$product_id] = stripslashes($row[product_title]); } else { mysql_query("UPDATE shopping_cart SET product_qty='$qty' WHERE cart_identifier='$cart_id' AND product_id='$product_id'"); } } if($error){ echo "<center>You have selected more than our current stock for the following product(s): <br />"; while(list($product_id, $product_title) = each($products)){ echo "<a href=\"/products.php?req=view&product_id=$product_id\">$product_title</a><br />"; } echo "<br />"; echo "We have updated your quantity to the maximum value that we have in stock.</center><br />"; echo "<center><a href=\"/cart.php\">Back to cart</a></center>"; } else { header ("Location: /cart.php"); } break; case "remove": $sql = mysql_query("DELETE FROM shopping_cart WHERE cart_identifier='$cart_id' AND product_id='{$_REQUEST['product_id']}'"); header("Location: /cart.php"); break; case "empty_confirm": echo "<center>Are you sure you want to empty your cart?<br />". "<a href=\"cart.php?req=empty\">Yes</a>". " | ". "<a href=\"/cart.php\">No</a></center>"; break; case "empty": $cart->empty_cart(); echo "<center>Your cart has been emptied!</center>"; break; default: if($cart_id){ $num_items = mysql_result(mysql_query("SELECT COUNT(*) as items FROM shopping_cart WHERE cart_identifier='$cart_id'"),0); if($num_items == 0){ echo "<center>Your shopping cart is empty!</center>"; exit(); } } else { echo "<center>Your shopping cart is empty</center>"; exit; } ?> <p>Your shopping cart</p> <p>This page allows you to modify or empty your shopping cart contents. Simply change the number of each product you wish to purchase and select the "update cart" link at the bottom.</p> <form name="update" method="post" action="/cart.php"> <table> <tr> <td>Qty</td> <td>Product</td> <td align="right">Price</td> <td align="right">Product Total</td> </tr> <?php $total = mysql_result(mysql_query("SELECT sum(product_qty * product_price) AS subtotal FROM shopping_cart WHERE cart_identifier='$cart_id'"), 0); $total = number_format($total, 2); $sql = mysql_query("SELECT * FROM shopping_cart WHERE cart_identifier='$cart_id'"); while ($row = mysql_fetch_array($sql)) { $product_total = number_format(($row[product_qty] * $row[product_price]), 2); echo "<tr><td><input type=\"text\" " . "name=\"qty[$row[product_id]]\" " . "size=\"2\" value=\"$row[product_qty]\" />" . "<br /><a href=\"/cart.php?req=remove&" . "product_id=$row[product_id]\">" . "Remove</a>" . "</td>" . "<td><a href=\"/products.php?req=view&product_id=$row[product_id]\">" . stripslashes($row[product_title]) . "</a></td>" . "<td align=\"right\">\$$row[product_price]</td>" . "<td align=\"right\">\$$product_total</td>" . "</tr>"; } ?> <tr> <td colspan="2"> </td> <td align="right">Total:</td> <td align="right">$<?=$total ?>< /td> </tr> <tr> <td colspan="4" align="center"> <a href="javascript:void(document.update.submit())">Update Cart</a> | <a href="/cart.php?req=empty_confirm">Empty Cart</a> | <a href="/products.php">Continue shopping</a> | <a href="/checkout.php">Checkout</a> </td> </tr> </table> </form> <?php break; } ?> Here is the add_cart function: function cart_add($product_id, $product_qty){ $cart_id = $this->get_cart_id(); if(!$cart_id){ //if no cart id found, generate one $unique_cid = md5(uniqid(rand(),1)); //set cart id into cookie setcookie('cid', $unique_cid, time()+24*3600*60); //Register session with cart id value $_SESSION['cid'] = $unique_cid; //if persion is a member //modify their profile with //cart id in the database if($_SESSION['login']){ $_SESSION['cid'] = $unique_cid; @mysql_query("UPDATE members SET cart_id='$unique_cid' WHERE id='".$_SESSION['userid']."'"); } }//end generate unique id $sql_get_product = mysql_query("SELECT * FROM shopping_products WHERE product_id='$product_id'"); $sql_check = mysql_query("SELECT * FROM shopping_cart WHERE cart_identifier='{$_SESSION['cid']}' AND product_id='$product_id'"); while($row = mysql_fetch_array($sql_check)){ $products = mysql_fetch_assoc($sql_get_product); if(($product_qty + $products[product_qty]) > $products[product_qty]){ $new_qty = $products[product_qty]; } else { $new_qty = ($product_qty + $row[product_qty]); } $sql = mysql_query("UPDATE shopping_cart SET product_qty='$new_qty', date = now() WHERE id='{$row['id']}'"); $skip = TRUE; } if(!$skip){ $products = mysql_fetch_assoc($sql_get_product); if($products[product_qty] < $product_qty){ $product_qty = $products[product_qty]; } if($product_qty > 0){ $sql = mysql_query("INSERT INTO shopping_cart (cart_identifier, product_id, product_title, product_qty, product_price, date) VALUES ('{$_SESSION['cid']}', '$product_id', '{$products['product_title']}', '$product_qty','{$products['product_price']}', now())"); } else { $sql = FALSE; } } if(!$sql){ return FALSE; } else { return TRUE; } }//end cart_add() My problem is that whenever I click the 'add' button to send the data across it seems like it isn't being sent correctly. I'm am a bit unsure on how to structure the url for the submit button and I think it's to do with that. These pages are being controlled around my index.php file and the products page url looks like this, 'index.php?content=products'. All my content files are in a folder named 'content'. Please ask for any other questions to aid my assistance. Much appreciated ! Sam
  15. They get stored as a session named as " product_'productid' " so how can I specifically target sessions beginning with 'product_' ?
×
×
  • 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.