Passing of variables... :S

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

border20
New php-forum User
New php-forum User
Posts: 32
Joined: Tue Jan 28, 2003 10:19 am
Location: Québec
Contact:

Passing of variables... :S

Postby border20 » Fri Jan 31, 2003 10:21 am

Hi I have th efollowind code and I dont know how to pass the variable... meaning that when i press the submit1 button, a value is given to $current and I want to reuse it later when I press submit2 but the $current no longer exists... how would i pass the variable ??

thx


<?php

if ($submit1){
$db = mysql_connect("localhost", "root");
mysql_select_db("mydb",$db);
$result=mysql_query("SELECT * FROM demande_action WHERE id=$id",$db);
$current = mysql_result($result,0,"id");
}

if($submit2){
$variable = $current +1;
}

User avatar
Joan Garnet
Moderator
Moderator
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars
Contact:

Postby Joan Garnet » Sat Feb 01, 2003 2:57 pm

When you press the submit button you re-send the form, and if there's no data in the field you won't pass anything.
If you want to keep the value use a link and send the variable via GET with a URL.

Code: Select all

<?php
//this one comes from a form
if ($HTTP_POST_VARS["submit1"]){
$db = mysql_connect("localhost", "root");
mysql_select_db("mydb",$db);
$result=mysql_query("SELECT * FROM demande_action WHERE id=$id",$db);
$current = mysql_result($result,0,"id");
echo "<a href='".$php_self."?my_variable=".$current."'>press</a>";
}
//this one comes from the link
if($HTTP_GET_VARS["my_variable"]);
$variable = $HTTP_GET_VARS["my_variable"] +1;
}
?>


Return to “PHP coding => General”

Who is online

Users browsing this forum: Google [Bot] and 1 guest