jhvn147 Posted July 13, 2012 Share Posted July 13, 2012 Hi everyone, I am new with php. I study it at Uni but have a problem. The code below is that of the 4 php files I created so far. The index takes you to the copper and steel pages, which can then take you to the cartaction page. This is a kind of shopping cart. My problem is that when I enter the values in the copper page, I can see them in the cartaction page - but if I now go to the steel page and enter values there, and then return to the cartaction page, the values from the copper page dissappeared. I have tried many combinations and I am sure you might help. Thank you. (jhvn147) Here is the code: index.php <?php session_start( ); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="styles/site.css" type="text/css" /> </head> <body> <div id="mainblock"> <table> <tr> <td> <a href="copperrange.php">C </a> </td> </tr> <tr> <td> <a href="steelrange.php">S </a> </td> </tr> </table> </div> <form method="post" action="cartaction.php"> <p> <input type="submit" name="submit" value="Show" /> <input type="hidden" name="cartaction" value="display" /> </p> </form> </body> </html> copperrange.php <?php session_start( ); if (isset($_SESSION['steelcasserole'])) { $_SESSION['steelcasserole'] = $_POST['steelcasserole']; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Copper</title> <link rel="stylesheet" href="styles/site.css" type="text/css" /> </head> <body> <table> <tr><td><?php echo "CpC: " . $_SESSION["coppercasserole"];?></td></tr> <tr><td><?php echo "Csp: " . $_SESSION["coppersaucepan"]; ?></td></tr> <tr><td><?php echo "Cs : " . $_SESSION["coppersaute"]; ?></td></tr> <tr> <form action="cartaction.php" method="post"> <input type="text" name="coppercasserole" value="<?php echo $_SESSION['coppercasserole']; ?>"> <input type="submit" value="View"> <form action="cartaction.php" method="post"> <input type="text" name="coppersaucepan" value="<?php echo $_SESSION['coppersaucepan']; ?>"> <input type="submit" value="View"> <form action="cartaction.php" method="post"> <input type="text" name="coppersaute" value="<?php echo $_SESSION['coppersaute']; ?>"> <input type="submit" value="View"> </tr> </table> <div id="footer"> <form method="post" action="cartaction.php"> <input type="submit" name="submit" value="Show" /> <input type="hidden" name="cartaction" value="display" /> </form> </div> <ul class="navlist"> <li><a href="index.php">Home</a></li> </ul></body></html> steelrange.php <?php session_start( ); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Steel</title> <link rel="stylesheet" href="styles/site.css" type="text/css" /> </head> <body> <table> <tr><td><?php echo "CpC: " . $_SESSION["steelcasserole"];?></td></tr> <tr><td><?php echo "Csp: " . $_SESSION["steelfrying"]; ?></td></tr> <tr> <form action="cartaction.php" method="post"> <input type="text" name="steelcasserole" value="<?php echo $_SESSION['steelcasserole']; ?>"> <input type="submit" value="View"> <form action="cartaction.php" method="post"> <input type="text" name="steelfrying" value="<?php echo $_SESSION['steelfrying']; ?>"> <input type="submit" value="View"> </tr> </table> <div id="footer"> <form method="post" action="cartaction.php"> <input type="submit" name="submit" value="Show" /> <input type="hidden" name="cartaction" value="display" /> </form> </div> <ul class="navlist"> <li><a href="index.php">Home</a></li> </ul></body></html> Quote Link to comment https://forums.phpfreaks.com/topic/265644-session-variable-lost-bewteen-3-pages-help-please/ Share on other sites More sharing options...
KevinM1 Posted July 14, 2012 Share Posted July 14, 2012 In the future, please place all code within tags. I took the liberty of adding them for you this time. Quote Link to comment https://forums.phpfreaks.com/topic/265644-session-variable-lost-bewteen-3-pages-help-please/#findComment-1361438 Share on other sites More sharing options...
jhvn147 Posted July 14, 2012 Author Share Posted July 14, 2012 Thank you sir, my first time here. jhvn147 Quote Link to comment https://forums.phpfreaks.com/topic/265644-session-variable-lost-bewteen-3-pages-help-please/#findComment-1361439 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.