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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Posted variables won't register in session...

Status
Not open for further replies.

tanuki3

Technical User
Dec 5, 2001
13
0
0
US
I have a PHP site in two pages. The first page is the query screen - a regular HTML form with several fields (basically an address database). The second page displays the results of the query although if there are more than 15 records, it generates pagination links. The initial results on the second page works correctly.

After the initial results screen, when the user clicks on one of the other results pages, I want it to pass the variables posted from the original page in the query. Instead, when I use session variables, it takes the values from the last row generated on the second page. I tried registering the query as a session variable, but this doesn't seem to do anything.

How do I register the values for the variables from the initial query on the first page (which used the post method) as session variables for use on the second page (and without them being overwritten by the last record generated on the second page)?

Any help would be appreciated.

FROM PAGE 1

<FORM ACTION="search2.php" METHOD="POST">
...
<INPUT size=37 name="S_Address">
...
<SELECT NAME="S_City">
...
<SELECT NAME="S_Zip">
...
<INPUT TYPE="submit" VALUE="Find">
...
<FORM>


FROM PAGE 2

$query = "SELECT * FROM [database] WHERE S_Address like '$S_Address_String' and S_City like '$S_City' and S_Zip like '$S_Zip_String'";
...
echo("<a href=\"$PHP_SELF?Xpage=$z\">$z</a>&nbsp\n");

[how pagination is displayed - $z is the page number. Based on its value, I use mysql_data_seek to move the recordset along to the next set of values]
...
$row = mysql_fetch_array ($result);
...
extract($row);
...
[results displayed at this point]
...




 
I appeared to solve my own problem, but maybe this will help someone else.

What was happening is that I used the same variable names on the first form as were in the database. This was done to keep it simple and worked fine before I put the pagination in. Of course once the pagination was done, when the database returned its values, it overwrote the session variable values from the first page with the values from the last row returned from the database.

I solved the problem by adding the prefix "Z_" to each variable name in the form on the first page. I also registered these Z_ variables as session variables on the second page, hence they survive anything else done with the secong page. And now the $query reads "...WHERE Z_City = City, etc.
 
Another solution is to pass the where portion of the sql statement in a hidden field, or pass the variables along in a hidden fields. Or append the data to the URL in the pagination links

Bastien

Cat, the other other white meat
 
Ummm, be careful in giving away too much with hidden fields. It's generally bad form to expose sql anywhere on the client side. Too many folks, like me, who 'view source' to see what I can see. Without the proper precautions, I could submit a form with an entirely different where clause that could really cause problems.

The same goes for anything that looks like sql in the URL.
 
I totally agree, majorBanzai, its merely a suggestion, based on things I've seen. I don't agee with it, and I made no mention of the security concerns as its more an option than anything else

Bastien

Cat, the other other white meat
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top