Jump to content

Session variable lost bewteen 3 pages - Help please


jhvn147

Recommended Posts

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.