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

Variables passed incorrectly

Status
Not open for further replies.

Kriekie

Technical User
Nov 21, 2004
10
ZA
Hi All!

I have the following php code in a form:
PHP:
$Limit = 1;
$Page = $_REQUEST["Page"];
if(empty($Page)) {$Page = 1; }
	
$Start = $Page / $Limit - 1;
if($Start <= 1) {$Start = 0;}

$list = mysql_query("SELECT * FROM detail LIMIT $Start, $Limit") or die(mysql_error());
$num = mysql_num_rows($list);
$rows = $num / $Limit;
$next = $Page * $Limit;

...

PHP:
if($Page > 1) {
$p = $Page - 1;

<input type="hidden" name="Page" value="
PHP:
 echo $p;
">
<input type="submit" name="Submit" value="Previous">

PHP:
if($next < $rows) {
$f = $Page + 1;

<input type="hidden" name="Page" value="
PHP:
 echo $f;
">
<input type="submit" name="Submit" value="Next">
PHP:
 }

The "next" button works fine, but the "previous" button acts weird. When pressed the first time, eg on page4, it will go to page 3. When pressed again on page3, it goes back to page 4....? I've added
PHP:
print $p;
and
PHP:
 print $Page
- $p outputs the correct page number : 2, but when submitted, $Page outputs "4" instead of "2"

Does any one know why this is?

Thnx!
 
You have several form elements that have the same name. Are they in the same form? That would be a problem.
You could use multiple forms or client side scripting to solve the problem. It needs to be discernable for the system which button was clicked to submit the form.

Please give feedback on how many forms there are etc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top