Jump to content

TheJoey

Members
  • Posts

    334
  • Joined

  • Last visited

    Never

Everything posted by TheJoey

  1. im unsure where i put my redirect. So i play it on the same page as my login script correct? Because when i try do that it doesnt allow me to use else <?php session_start(); $username = $_POST['username']; $password = $_POST['password']; $lines = file("users.txt",FILE_IGNORE_NEW_LINES); // read the lines into an array $find = "$username:$password"; // form a string like you expect it to be in the array if(in_array($find,$lines)){ $_SESSION['loginsuccessfull'] = true; { if(!$_SESSION["loginsuccessfull"]) header("location: loginsuccess.php"); } else { $_SESSION["loginsuccessfull"] header("location: loginunsuccess.php"); } ?> ive never used a header before sorry
  2. Your answer seems like a solution ill give it a go thanks. ill keep you posted
  3. It is using a session, or so i thought. Well im currently not at home, the css works fine in html. That double echo may be a problem ill have a look. How may i fix the loggin?
  4. Ive been trying to do this but it just doesnt show up the same as it does when i do it in html. <?php session_start(); ?> <html> <head> <link rel="stylesheet" href="assets/css/style.css" type="text/css" media="all" /> </head> <body> <?php $username = $_POST['username']; $password = $_POST['password']; $lines = file("users.txt",FILE_IGNORE_NEW_LINES); // read the lines into an array $find = "$username:$password"; // form a string like you expect it to be in the array if(in_array($find,$lines)){ $_SESSION['loginsuccessfull'] = true; echo echo '<div id="wrapper"> <div id="header"> <p class="logotext">NEw Stop <strong>Shop</strong><br> <span class="logotext2">Blah blah blah</span></p> <div id="nav"> <ul> <li><a href="">Site Map</a></li> <li><a href="">Privacy Policy</a></li> <li><a href="">Products</a></li> <li><a href="">Registration</a></li> <li><a href="index.html" class="on">Home</a></li> </ul> </div> </div> <div id="content"> <div id="left"> <h2>Addition Links</h2> <ul> <li><a href="">WHOOP WHOPP</a></li> <li><a href="">LOCATE US</a></li> <li><a href="">= Us</a></li> <li><a href="">2Us</a></li> </li> </ul> </div> <div id="breadcrumb"><strong>Home</strong></div> <div id="right"> <h1>NEW STOP SHOP</h1> <p>Login successfull</p> </div>'; } else { echo '<div id="wrapper"> <div id="header"> <p class="logotext">NEw Stop <strong>Shop</strong><br> <span class="logotext2">Blah blah blah</span></p> <div id="nav"> <ul> <li><a href="">Site Map</a></li> <li><a href="">Privacy Policy</a></li> <li><a href="">Products</a></li> <li><a href="">Registration</a></li> <li><a href="index.html" class="on">Home</a></li> </ul> </div> </div> <div id="content"> <div id="left"> <h2>Addition Links</h2> <ul> <li><a href="">WHOOP WHOPP</a></li> <li><a href="">LOCATE US</a></li> <li><a href="">= Us</a></li> <li><a href="">2Us</a></li> </li> </ul> </div> <div id="breadcrumb"><strong>Home</strong></div> <div id="right"> <h1>NEW STOP SHOP</h1> <p>Login Unsuccesfull</p> </div>'; } ?> </body> </html> Also when i click to go home, it gives me echo's "login unsuccessfull" before sending me back to home.
  5. I have a shopping cart that uses sessions to store information. How would i pass on information to product a mini basket to view all items and checkout, if someone could point me in the right direction. <?php session_start(); //////////////// Brand new session - offer login if (! $_SESSION[active]) { $_SESSION[active] = 1; $heading = "Welcome - please log in"; $htmlsay = "Please enter your name <input name=whoareyou>"; } else { //////////////// Name has been entered - store it if (! $_SESSION[uname]) { $_SESSION[uname] = $_REQUEST[whoareyou]; $_SESSION[cart] = array(); } /////////////// Report purchases so far $offering = array ("apple","banana","cherry","damson"); $buy = $_REQUEST[buy]; if ($buy != "") $_SESSION[cart][$buy]++; $heading = "You have ... "; foreach ($offering as $fruit) { if ($_SESSION[cart][$fruit] > 0) { $heading .= $_SESSION[cart][$fruit]." $fruit, "; $npf ++; } } if ($npf < 1) $heading .= " nothing in your shopping basket yet"; $htmlsay = ""; ///////////////// If not checking out, offer more purchases if ($_REQUEST[next] != "checkout") { $heading .= "<BR>Please select a piece of fruit"; foreach ($offering as $fruit) { $htmlsay .= "<input type=radio name=buy value=$fruit> $fruit<BR>"; } $htmlsay .= "<input type=submit name=next value=add>"; $htmlsay .= "<input type=submit name=next value=checkout>"; ///////////// If checking out, clear session //// (Live application would go on to delivery info, etc) } else { $htmlsay = "$_SESSION[uname], Your order is placed. Thank you for shopping with us<BR>"; $htmlsay .= "<input type=submit name=next value=continue>"; session_destroy(); } } //////////// Following is the HTML! ?> <title>Session based shopping cart</title> <body bgcolor=white > <h2>Demonstration of a session</h2> <?php echo $heading;?> <form method=post action="<?php echo $PHP_SELF;?>"> <?php echo $htmlsay;?> </form> </body>
  6. Thanks guys just needed confirmation of it
  7. should just add them to code tags "[" code ][" /code]"
  8. can i call up a session from a previous page? And another thing could i implement the code you gave me as. if (isset($_SESSION['logged']]) { // show whatever (ALL CART CODE WITH SUBMIT BUTTONS) } else { (ALL CART CODE WITHOUT SUBMIT BUTTONS) }
  9. I have a quick question. im using sessions in my shopping cart. Can i make it that if someone is not logged in that the sumbit buttons are disable or something similar. i want to give guest ability to view just not to sumbit.
  10. there isnt a error but inside the text box where the quanity number goes it displays <?=item?> insted
  11. yeah i was having a world of trouble with the session and url. thanks dave.
  12. The quanity add doesnt seem to work to well. i havent changed the code.
  13. thanks dude. Still some tweeks needed to be done but provides a good platform for me thanks again.
  14. Well the main problem is that once i add a item. i can remove it but after that its not possible for me to add another item to be removed. its very messy so far.
  15. Could you please explain what that is doing. im kinda new to sessions.
  16. i placed that bottom of my page and it didnt effect it.
  17. i currently working with this very simple but im having trouble trying to implement qty amount into it. Also another trouble im having it once i add a item i cant add another one. Hope you guys can help. Thanks in advance <?php error_reporting(E_ALL); ini_set('display_errors', '1'); session_start(); $_SESSION['shopping_cart'] = array(); // And then to add items... $_SESSION['shopping_cart'][] = "Ball"; $_SESSION['shopping_cart'][] = "Shoe"; // And to echo them back out... foreach($_SESSION['shopping_cart'] as $value); ?> <html> <body> <table> <tr> <td><a href='<?PHP echo $_SERVER['REQUEST_URI']; ?>?action=add_to_cart&item=Ball'>Add Ball To Cart</a></td> </br> </tr> <tr> <td><a href='<?PHP echo $_SERVER['REQUEST_URI']; ?>?action=add_to_cart&item=Shoe'>Add Shoe To Cart</a></td> </tr> <tr> <td><select name="qty"><option value="0">--</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option></select></td></tr> </tr> </body> </html> <?php if($_GET['action'] == "add_to_cart") { $_SESSION['shopping_cart'][] = $_GET['item']; } ?> <?php foreach($_SESSION['shopping_cart'] as $key => $value) { echo '<br> </br>'; echo $value . "<a href='" . $_SERVER['REQUEST_URI'] . "&action=remove_item&itemkey=" . $key ."'>Remove</a>"; } if($_GET['action'] == "remove_item") { unset($_SESSION['shopping_cart'][$_GET['itemkey']]); } $_SESSION['shopping_cart'] = array(); ?>
  18. never mind the ? fixed the issue. Just gotta play around with what i got. Thanks for your help dave your a legend man.
  19. the problem is that when i click the link i get Object not found!
  20. <a href='<?PHP echo $_SERVER['REQUEST_URI']; ?>&action=add_to_cart&item=ItemName'>Add To Cart Link</a> im having problems with this line of code. Do i have to define Item? as the items i have stored? <?php error_reporting(E_ALL); ini_set('display_errors', '1'); session_start(); $_SESSION['shopping_cart'] = array(); // And then to add items... $_SESSION['shopping_cart'][] = "Ball"; $_SESSION['shopping_cart'][] = "Shoe"; // And to echo them back out... foreach($_SESSION['shopping_cart'] as $value) { echo $value . "<br />"; } ?> <html> <head> </head> <body> <a href='<?PHP echo $_SERVER['REQUEST_URI']; ?>&action=add_to_cart&item=Ball'>Add To Cart Link</a> </body> <?php if($_GET['action'] == "add_to_cart") { $_SESSION['shopping_cart'][] = $_GET['item']; } ?> <?php foreach($_SESSION['shopping_cart'] as $key => $value) { echo $value . "<a href='" . $_SERVER['REQUEST_URI'] . "&action=remove_item&itemkey=" . $key ."'>Remove</a>"; } if($_GET['action'] == "remove_item") { unset($_SESSION['shopping_cart'][$_GET['itemkey']]); } ?>
  21. Thanks for your help dave, ill keep you posted. So you think i shouldnt store my arrays like i have and just do it the way you have correct ? ill give it a go! cheers
  22. i have absolute no idea how to do it. well there is going to be about 6 items. The only problem is that i can write a database driven shopping cart. But get completly stuck when using arrays this way. Do you have a different way it can be done?
  23. Well i thought i could start by producing the arrays would i then be able to use this code <?php //These bunch of arrays act as a database. $categories=array(); $categories[]='Socks'; $categories[]='Shoes'; $catergories[]='Ball'; $products=array(); $products['item1']['category']='socks1'; $products['item1']['sizes']='0,1,2,3,4'; $products['item1']['price']='2'; $products['item1']['category']='shoe1'; $products['item1']['sizes']='0,1,2,3,4'; $products['item1']['price']='3'; $products['item1']['category']='ball1'; $products['item1']['sizes']='0,1,2,3,4'; $products['item1']['price']='4'; ?> to act as a database?
×
×
  • 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.