How can I pass a veriable -----

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
dilruk83
Forum Newbie
Posts: 13
Joined: Thu Oct 30, 2008 6:44 am

How can I pass a veriable -----

Post by dilruk83 »

I have two buttons named 'go' and 'sub' and one form to do this.At same form i have two click events.

echo "<input type='submit' name='go' id='go' value='Go' />"; // button go

echo "<input type="submit" name="sub" id="button" value="Submit" />"; // button sub

echo "<input type='text' name='type' id='type' value='$router' />"; // This is a texbox. This value-$router pass from a list box

if (isset($_POST['go'])) // when user click on go button
{
$r=$_POST['type'];
echo $r; // this printed $r value.
}

if (isset($_POST['sub']))
{

// problem is...
// How can i get $r value to here...?

echo "Router : ".$r; // I got null value for this

// How can i get $r value to this click event..?


}
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: How can I pass a veriable -----

Post by Eric! »

While your code doesn't really make sense to me, your "$r" variable is actually stored in $_POST['type']. As long as that value is set, you can access it all day. My guess is your problem with "$router". It isn't defined anywhere in the stuff you posted. Or the problem is that the if-loop you're having trouble with runs before or outside of where $r is defined. Try redefining $r=$_POST['type'] inside the if-loop where you are having trouble.

Also, learn to use the [syntax=php]PASTE CODE HERE[/syntax] tags for posting.
Post Reply