Jump to content

Samza

Members
  • Posts

    26
  • Joined

  • Last visited

Everything posted by Samza

  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_' ?
  16. Okay this didn't make a difference :S I think the problem is to do with the login session variables which are being compared against my variables for each product in a cart which is being added upon a hyperlink.
  17. I haven't manually set this myself so I'm guessing not. I am using xampp. Would this help ?
  18. Hi, I am following the PHP Academy tutorial on youtube, and I'm on part 4 (http://www.youtube.com/watch?v=cJJKQ8MXGrE). However, I am running into a bit of a problem as I have other session variables for my user login and when I am using the foreach statement I dont want to include the login session variables if you understand, only the product_ variables function cart() { foreach($_SESSION as $name => $value) { if ($value>1) { if (substr($name, 0, =='product_'){ $id = substr($name, 8, (strlen($name)-); echo '<br />'.$id; } } else { echo "Your cart is empty! <br />"; echo $name.': has a value of :'.$value; } } } and this is displayed: As you can see it's also using the login session variables which is causing some issues for me because it's displaying that the cart is empty when it is not! So i'm a bit stuck as to what to do :S Sam-
  19. When I was saying it was only displaying data that was ODD or EVEN by 'id' I meant it would display like id row 1 id row 3 id row 5 or id row 2 id row 4 id row 6 I changed that line as you suggested and it now works echo "<a href='cart_index.php?add=".$result_row['id']."'>Add to cart</a>"; Why doesn't it get parsed if it's in single quotes? and thanks for your advice
  20. Hi, Okay so I have my database properly set up and I have tested that there is nothing wrong with my sql query. But, whenever I try to display data from the database it will only show even or odd 'id' number rows. this is my php code simplified and it still doesn't work: <?php include '../connection.php'; session_start(); $page = 'index.php'; $query = "SELECT id, productname, price, screensize, description, shipping, quantity FROM products WHERE quantity > 0 ORDER BY id ASC"; $result = mysql_query($query); while ($result_row = mysql_fetch_assoc($result)) { echo "<p>"; echo '<a href="shoppingcart.php?add='.$result_row['id'].'>Add to cart </a>'; echo $result_row["id"]; echo "<br />"; echo $result_row["productname"]; echo "<br />"; echo $result_row["screensize"]; echo "<br />"; echo $result_row["description"]. "<br/>"; echo "£" .number_format($result_row["price"], 2); echo "</p>"; echo "<hr>"; } ?> I found out that the problem was with the this line: echo '<a href="shoppingcart.php?add='.$result_row['id'].'>Add to cart </a>'; And if I inserted it before the 'id' to display it would only show the even numbered 'id' rows and odd if I entered it after. I am stuck for any ideas and I think I need someone with experience who knows how to sort this problem out. Thanks Sam.
  21. Thanks mate! I'm also looking to display the user's password however I have multiple encryption's with a salt on it. Would I have to create a reverse function to display it in the form for them to edit, or should I not show their password for safety?
  22. Hi, I am fairly new to PHP and I can't for the life of me correct this error: "Parse error: syntax error, unexpected '$username' (T_VARIABLE) in D:\Computer Forensics\xampp\htdocs\xampp\iis\php\userprofile.php on line 7" Here is the corrosponding file code: <?php include 'connection.php'; ?> <?php $username = $_SESSION['authenticatedUser']; $query = 'SELECT firstname, surname, username, password, email, address1, address2, postcode FROM customers WHERE username='$username' LIMIT 1'; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { $username = $row['username']; } ?> <html> <table border=1> <tr> <th>Username</th><td><input type="text" name="username" value="<?php echo $_SESSION["authenticatedUser"] ?>" /></td> </tr> </table> </html> I have tried using the $_SESSION variable instead of $username and alternated the quotation marks etc but it still has no affect. It would be much appreciated if anyone could help me out. Thanks, Sam.
  23. I'm having basically the same error. I get this; "Sql ErrorUnknown column 'sentto' in 'field list'". What can I do?
  24. Okay this is my login file <?php session_start(); //must call session_start before using any $_SESSION variables $_SESSION ['loggedin'] = 'loggedin'; $username = $_POST['username']; $password = $_POST['password']; $userid = $_POST['userid']; //validating a user function validateUser() { session_regenerate_id (); //this is a security measure $_SESSION['valid'] = 1; $_SESSION['userid'] = $userid; } //connection to the database include 'connection.php'; $username = mysql_real_escape_string($username); $query = "SELECT id, password, salt FROM users WHERE username = '$username';"; $result = mysql_query($query); if(mysql_num_rows($result) < 1) //no such user exists { header('Location: incorrectlogin.php'); die(); } $userData = mysql_fetch_array($result, MYSQL_ASSOC); $hash = hash('sha256', $userData['salt'] . hash('sha256', $password) ); if($hash != $userData['password']) //incorrect password { header('Location: incorrectlogin.php'); die(); } else { validateUser(); //sets the session data for this user } //login successful ?> Notice: Undefined index: userid in ..\..\. on line 7 $userid = $_POST['userid']; Notice: Undefined variable: userid in ..\..\. on line 14 $_SESSION['userid'] = $userid; I'm not sure why it's not working because I have declared it before the function.
×
×
  • 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.