[Solved] HTML hitting both forms' submit buttons ?!

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Da P3s7
Forum Commoner
Posts: 30
Joined: Wed Jul 19, 2006 3:25 pm
Location: /usr/src/kernels/ 2.6.15-1.2054_FC5-i686

[Solved] HTML hitting both forms' submit buttons ?!

Post by Da P3s7 »

I have this html code

Code: Select all

$h = $_POST['h'];
$plusmine = $_POST['plusmine'];
If ($plusmine == "-1") //if the button back is pressed
{
	If ($h < 0)
	{
		echo ""; //do nothing (is there any other way to say do nothing ?)
	}
	Else
	{
	$a = $h - 1; //decrease page counter by 1
	echo "aa";
	}
}
If ($plusmine == "+1")
{
	$b = $h + 1; //increase page counter by 1
	echo "bb";
}

If ($h < 1)   //if i'm running it first time dont get a back button
	{
	echo "";
	echo "";
	}
Else        //otherwise show it
	{
	echo "<form action='insert.php' method='POST'>";
	echo "<input type='hidden' name='plusmine' Value='-1'>";
	echo "<input type='hidden' name='h' value = '$a'>";
	echo "<input type='submit' value='Back' name='back'> ";
	echo "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp";
	} // the &nbsp is to make a pretty big space between back and next button... so theyre not easily confused)
If ($h != $numrows)  //$numrows comes from a mysql_num_rows() call.
	{
	echo "<form action='insert.php' method='POST'>";
	echo "<input type='hidden' name='plusmine' Value='+1'>";
	echo "<input type='hidden' name='h' value = '$b'>";
	echo "<input type='submit' value='Next' name='next'> ";
	}
//so if the page im on is the total number of pages dont show the next button (nowhere to go anyway! =) )
Well the thing is that when i echo the $plusmine var i get +1 in EVERY case. I push next its doing what it's supposed to be doing...
Increase the counter.
If i press back it still increases the counter!!!

This is the result from echoing:

1st run(page 0) :
I get nothing..logical as variables arent set yet
Pressing next(page 1):

Code: Select all

+1bb
And no back button (!!!)
Pressing next(on page 1 to 2)

Code: Select all

+11bb
The +1 is the plusmine the 1 next to it is the h and bb is from the echo of the IF statements.
Pressing back (on page 2 to 1)

Code: Select all

+12bb
And the page is 2 !!!! :!: :!: :!: :!:
And so on....

Can anybody help me sort this out?...
Last edited by Da P3s7 on Thu Aug 03, 2006 10:18 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You're missing </form> tags.
User avatar
Da P3s7
Forum Commoner
Posts: 30
Joined: Wed Jul 19, 2006 3:25 pm
Location: /usr/src/kernels/ 2.6.15-1.2054_FC5-i686

Post by Da P3s7 »

OK....ill strangle myself.... :mrgreen: :oops: :mrgreen: :| :| :| :| :|
Ok that seems to change the thing a bit....now whenever i press back it resets the $h variable 8O
Any help on that?

(still can't shake it: was so easy)

Edit:
Solved!!!
Changed the $a and $b to $h. It worked... Thx anyway
Post Reply