Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

refresh wipes display?

Posted on 2011-03-18
3
Medium Priority
?
253 Views
Last Modified: 2012-05-11
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

0
Comment
Question by:pillmill
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 35169291
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

0
 
LVL 20

Accepted Solution

by:
Mark Brady earned 2000 total points
ID: 35171219
The best way I have ever seen is to use php sessions. Sessions store posted data in session variables so as long as you open a session on the page it will retain the form data in each input field. Here is how you do it. I have made a very quick example with only first and last names just to show you how it keeps the data. Save the attached file "session.php" in the same folder as this php script.

<?php // this is your php script with the form in it.
include("session.php"); // important - don't forget to add this line.

// just for this test
$first = $_POST['first'];
$last = $_POST['last'];
if($first != "" && $last != "") echo "Hello ".$first." ".$last;

// Put all your form processing code here.
?>
<!-- now the form -->
<form method="POST">
Firstname <input name="first" type="text" value="<?php echo $_SESSION['first'];?>" />
Lastname <input name="last" type="text" value="<?php echo $_SESSION['last'];?>" />
<input type="submit" value="Submit" /></form>



That's it. Save it as some name.php and run it. Fill in the two fields and submit the form. session.php
0
 
LVL 20

Expert Comment

by:Mark Brady
ID: 35171227
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.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question