Link to home
Start Free TrialLog in
Avatar of pillmill
pillmill

asked on

refresh wipes display?

I have a simple, editable, html table (see attached).

When submit is pressed to save data, the page
is refreshed and the display data is lost.

How can the display be retained after submit?
<td><input type="text" name="r1c1" /></td>
<td><input type="text" name="r1c2" /></td>
<td><input type="submit" value="save"/> </td>
</tr>
<tr>
<td><input type="text" name="r2c1" /></td>
<td><input type="text" name="r2c2" /></td>
<td><input type="submit" value="save"/></td>

Open in new window

Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Here's one way.  Save as 'postdata.php' or something '*.php' and run it on your server.
<?php 

$r1c1 = "";
$r1c2 = "";
$r2c1 = "";
$r2c2 = "";

if(isset($_POST["submit"])) {
	if(isset($_POST["r1c1"])) $r1c1 = $_POST["r1c1"];
	if(isset($_POST["r1c2"])) $r1c2 = $_POST["r1c2"];
	if(isset($_POST["r2c1"])) $r2c1 = $_POST["r2c1"];
	if(isset($_POST["r2c2"])) $r2c2 = $_POST["r2c2"];
	}
 ?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>Post Data</title>
</head>
<body>
<h1>Post Data</h1>

<form action="" method="post">

<table border="0" cellpadding="0" cellspacing="0" summary="">
<tr>
<td><input type="text" name="r1c1" value="<?php echo $r1c1; ?>" /></td>
<td><input type="text" name="r1c2" value="<?php echo $r1c2; ?>" /></td>
<td><input type="submit" name="submit" value="save"/> </td>
</tr>
<tr>
<td><input type="text" name="r2c1" value="<?php echo $r2c1; ?>" /></td>
<td><input type="text" name="r2c2" value="<?php echo $r2c2; ?>" /></td>
<td><input type="submit" name="submit" value="save"/></td>
</tr>
</table>

</form>
</body>
</html>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Mark Brady
Mark Brady
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The beauty of doing it this way as opposed to DaveBaldwins method is that you can use this posted data on any other page on your website. As long as you include that session.php file on a php page you can get the data. Whatever the name of your input fields, is the name of the session variable. So on a completely different page you can do this.

<?php
include("session.php");
// some code goes here. Now if you want to know what was posted in that other form just do this:

$first = $_SESSION['first'];
$last = $_SESSION['last'];

// it takes place of the usual $_POST['first']; and it remains in that session variable until you close the browser or you kill the session.

session_destroy();

that will end the session and all variables inside it. Hope this is what you are looking for.