Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php mysql variable echo question I guess

Status
Not open for further replies.

RogueDogg1

Programmer
Jul 13, 2006
11
US
I have a variable that is passed via $_POST[FirstName] from apage2.php to it'self and now I do some edits to that page and submit that to apage3.php but the variable doesn't come across to the next page...how come?
Example:
db query to get firstname in a form then using the post method I submit that to the same page. Then add some features ( not changing the firstname variable at all ) and submit that form ( 2 total forms now ) using the post method as well. So we've got 2 forms with a total of 2 php files. I've tried using hidden values on the 1st php page to the 2nd php page but that doesn't work ( unless I'm doing it wrong ). Any Ideas?


Here is a simple live verison of it with the same issue:
I got rid of one php page but no matter it's still the same issue. So what you do is click on the first submit button and it now displays the website that was query'd from the database, now add some new text to the text box and click on the second submit button, you will notice only the text box variable is being passed to the 3rd page. Here is the code for the 2 pages:

test2.php
Code:
<? 
$db = mysql_connect ("localhost","dbuser","dbpword") or die(mysql_error()); 
$link = mysql_select_db ("cashflow_misc", $db) or die(mysql_error()); 
$query = "select website FROM websites"; 
$result = mysql_query($query); 
$website = mysql_result ($result, 0); 
?> 
<form method="post" name="website" action="<? echo $_SERVER['PHP_SELF'];?>"> 
Database query complete press submit to see your website below: 
<input type="hidden" name="website" value="<? echo "$website";?>" /> 
<input type="submit" name="add_website" value="submit" /> 
</form> 
<br /> 
<br /> 
<form method="post" name="test" action="test3.php"> 
This is your website: <? echo $_POST['website'];?> 
<br /> 
<br /> 

<input type="text" name="test" maxlength="18" value="blah test" /> 
<input type="submit" name="test2" value="submit" /> 
</form>

Here is the code for test3.php:
Code:
<? 
echo "$website";?> this should be your website <br /> 
<? echo "$test";?>

Hope that helps anyone understand my problem(s).
 
You haven't preserved the posted value in any fashion.

There are several ways to do that:
1. Use sessions. Store the posted value in a session variable and access it via the $_SESSION superglobal array or
2. Write out HTML, a hidden field which preserves the posted value:
Code:
echo "<input type='hidden' name='whatever' value='".$_POST[FirstName].'"'.;

Ok?
 
Isnt't that what I did on test2.php?

Code:
<input type="hidden" name="website" value="<? echo "$website";?>" />
 
Your hidden field is in the first form. The input elements are only known to the surrounding form tag.
Move the hidden tag into the second form and you'll be fine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top