Hi guys,

Could anyone help me out with this...

I have a multi form, which the user enter in the data and submits the data.. It also have a save button in it.. so user can save and then come back,.. then can save again, or submit..

I saved the data to a table in db.. when the user comes again...the data has to be reloaded in the textfield, that is retrieve...

so i used...

<input type="text" name="aa" value="<?php echo "$ss_address"; ?>" />

which is retrieve the data from database..
since it is a multi form,
when i change the data in the text field, and go to next page and come back.. the data doesnt change... its still the old data which is retrieved from the db..

I know., it something with passing session..

Can someone help me out..
I have posted the codes below:

pg1.php

<?php
session_start();
?>
<?php 
include "base.php"; 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
$txt_name = $_SESSION['txt_name'];
echo "$txt_name";
$query  = "SELECT p_id,id,company_country,Project_title,total_grant,partner_company,end_date,c_name FROM create_project where c_name ='$txt_name'";
$result = mysql_query($query);
if($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
            $p_id = $row['p_id'];
			$id = $row['id'];
			echo "Project ID: $p_id";
			echo "<br>";
			echo "Company ID: $id";
			echo "<br>";  
}
?>
<?php
$saved_query = "SELECT * FROM creator_save WHERE p_id ='$p_id' AND id = '$id' AND status = 'saved'";
$saved_result = mysql_query($saved_query);
while($saved_row = mysql_fetch_array($saved_result))
{
$ss_address = $saved_row['creator_address'];
$ss_name = $saved_row['tm_name'];
//$_SESSION['address'] = $ss_address;
//echo"$ss_address";
}
?>
<form id="form1" name="form1" method="post" action="">
  <label>
  a: 
  <input type="text" name="aa" value="<?php echo "$ss_address"; ?>" />
  </label>
  <p>
    B:
    <input type="text" name="bb" value="<?php echo "$ss_name"; ?>" />
  </p>
  <p><a href="pg2.php">PG2 &gt; </a></p>
</form>
</body>
</html>

pg2.php

<?php
session_start();
?>
<?php include "base.php"; ?>
<?php
//if (!isset($_SESSION['address']) || isset($_POST['a'])) {
//	$_SESSION['address'] = $_POST['aa'];
	//$add = $_SESSION['address'];
//}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
$txt_name = $_SESSION['txt_name'];
echo "$txt_name";
//echo "$add";
$query  = "SELECT p_id,id,company_country,Project_title,total_grant,partner_company,end_date,c_name FROM create_project where c_name ='$txt_name'";
$result = mysql_query($query);
if($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
            $p_id = $row['p_id'];
			$id = $row['id'];
			echo "Project ID: $p_id";
			echo "<br>";
			echo "Company ID: $id";
			echo "<br>";  
}
?>
<?php
$saved_query = "SELECT * FROM creator_save WHERE p_id ='$p_id' AND id = '$id' AND status = 'saved'";
$saved_result = mysql_query($saved_query);
while($saved_row = mysql_fetch_array($saved_result))
{
$ss_design = $saved_row['tm_design'];
$ss_email = $saved_row['tm_email'];
//$_SESSION['address'] = $ss_address;
//echo"$ss_address";
}
?>
<form id="form1" name="form1" method="post" action="">
  <label>
  c:
  <input type="text" name="c" id="c" value="<?php echo "$ss_design"; ?>" />
  </label>
  <p>
    D: 
    <input type="text" name="d" id="d" value="<?php echo "$ss_email"; ?>"/>
  </p>
  <p><a href="pg1.php">&lt; PG1</a></p>
</form>
</body>
</html>

Thanks for ur help..
:)

Tryphy

Recommended Answers

All 11 Replies

Because you are always retrieving the data from the database and showing in that field, If you want to populate your data, every time you need to update or save your data in your DB.

Because you are always retrieving the data from the database and showing in that field, If you want to populate your data, every time you need to update or save your data in your DB.

Hi saiprem,,

Thanks for the reply...
Can u help me with the code, how to do it..?

Member Avatar for diafol

Either that or place said variables into a session for retrieval

Either that or place said variables into a session for retrieval

Yes, i know its like somewhat using session.. for retrieval..
Could u pls, guide mw with the code..
Thanks for your help..
I gotta finish this by today..
Do help me kindly.. thanks..
:)

It is so simple, just add this loop

foreach($values as $keys=>$val)
{
    unset($_SESSION[$keys]);
    $_SESSION[$keys] = $val;
}

 return count($errors);

It is so simple, just add this loop at the end of your verifyform function

foreach($values as $keys=>$val)
{
    unset($_SESSION[$keys]);
    $_SESSION[$keys] = $val;
}

 return count($errors);

Thanks, saiprem....
sry wat do u mean by the verify form function
:(

Thanks, saiprem....
sry wat do u mean by the verify form function
:(

Sorry I edited it again and removed that in my post check it again...:)

Sorry I edited it again and removed that in my post check it again...:)

HI sai,.

Where exactly the code has as be copied..


What does the variable: values, keys, val ...define... ?
Guide me with this.. as i m not sure how to do it ...

I am assuming that DB column names are equals to Form elements names

Initially read the values from the database and assign those column names and values to $values(perform this only once)
Ex :
$values[columnname] = 'actual_databasevalue';

After finishing the above retrieving of data, then call the for loop which i have given in my previous post. By executing that loop all the DB values are stored in the session array. Now you will have the DB values in your session array.

Where ever you want to put those session values, just put them in their respective fields. If you edit a field and go to next page just pass the edit value to the next page and assign the same to session array again, this way you need to carry the data in a session.

Finally when you are saving the data, just pass the session array values to save in your DB.

HI saiprem...

Thanks for ur reply...
I worked with the code, as you said...

$values['creator_address'] = '$ss_address';
$values['tm_name'] = '$ss_name';

 foreach($values as $keys=>$val)
{
    unset($_SESSION[$keys]);
    $_SESSION[$keys] = $val;
}

notsure, if it is correct or wrong...
It doesnt work... I m totally lost....
Could you please.. help me with the codes... can u add the codes, in the pg1.php and pg2.php.... of my first posting.. and let me know...Pls help me with it.. Thanks...
and not sure how to use the session...while passing to the next page...

HI saiprem...

Thanks for ur reply...
I worked with the code, as you said...

$values['creator_address'] = '$ss_address';
$values['tm_name'] = '$ss_name';

 foreach($values as $keys=>$val)
{
    unset($_SESSION[$keys]);
    $_SESSION[$keys] = $val;
}

notsure, if it is correct or wrong...
It doesnt work... I m totally lost....
Could you please.. help me with the codes... can u add the codes, in the pg1.php and pg2.php.... of my first posting.. and let me know...Pls help me with it.. Thanks...
and not sure how to use the session...while passing to the next page...

Oh, I am sorry to say that I can't write everything and give it to you,

The way you implemented is correct, but assigning the values in a loop should work only once when the page is loaded(initially).
We should not execute for loop everytime when page is loaded.

Now you will have values in your session array, you can put that session values to your text box values, when ever you are navigating to next page (submitted the form), you need to assign all the form values again in session array, this way session will be updated everytime when you move from one page to another page.

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.