Hi guys,

I have a page that echos fields from a database based on various text and combo box selections. I am trying to get it so that when the page is refreshed, the echoed vales are still displayed, even if the form fields are reset.

Im under the impression that i need to use cookies to acheive this however all the code I find via google only lets me display cookie values.

The code i use to display the database values is as follows:

<?php
				mysql_connect ("localhost", "pegasus","123456")  or die (mysql_error());
				mysql_select_db ("partslist");

				if ($term == "") {
				echo "";
				}
				else {
 
				$sql = mysql_query("select * from $table where part like '$term'");
  
				while ($row = mysql_fetch_array($sql)){
			?>
			<div id="display-part"><?php echo $row['part'] .'&nbsp;'.$table; ?></div>
			<div id="display-partno"><?php echo $row['partno']; ?></div>
			<div id="display-alternative"><?php echo $row['alternative']; ?></div>
			<?php
			}
			}
			?>

All help is greatly appreciated.

You could display it via sessions instead of cookies which I find much more convenient. Or you could integrate the whole thing with AJAX if you know your way around JavaScript.

Member Avatar for rajarajan2017

You can retain the values even after refresh using AJAX

Hi guys thanks for the replys.

gunnarflax: I have spent all morning trying to keep the values with sessions however I have had no luck.

rajarajan07: do you know any example code that could help me with this. I have tried to search google however I cant seem to find anything.

Thanks

just unset the $term at the end of your code like,

unset($term);

If your problem has been solved, please also mark the thread as solved :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.