swatisonee Posted March 24, 2006 Share Posted March 24, 2006 Hi,I have the foll. code that works perfectly *except* that the hidden value $uid doesnt pass thru. When this script is run , i can see the value of $uid in the address bar and also when i use $_GEt, the value gets echoed but thereafter, it appears to be completely ignored by the rest of the script. Could someone tell me what could be the reason and how i could correct it ?I have passed the hidden field both within and outside the form tags hoping one of them would be right but none worked - have left all of them in this script for anyone else to have a look to see which will definitely not workThanks Swati[code]<? include("protect.php");$uid = $_GET["uid"];echo $uid;if(isset($_POST) && !empty($_POST["customer"])){?><input type="hidden" name="uid" value="<? echo $uid ?>" ><b><p><font face="Tahoma" size="2" color="#0000FF">These are the customers in your database in the selected alphabet range. Select one to update</b></font><p><form method="post" action="update_new1.php?uid=<? echo $uid ?>"><table border="1" style="border-collapse: collapse" bordercolor="#111111" width="100%"><tr bgcolor="#DEEDFE"><td><b><font size=2 face=Tahoma color=blue>Select</b></td><td><b><font size=2 face=Tahoma color=blue>Company</b></td><td><b><font size=2 face=Tahoma color=blue>City</b></td><td><b><font size=2 face=Tahoma color=blue>State</b></td><td><b><font size=2 face=Tahoma color=blue>First Name</b></td><td><b><font size=2 face=Tahoma color=blue>Last Name</b></td><tr><?phpmysql_connect("localhost", $dbname, $dbpasswd ) or die ("Unable to connect to server.");mysql_select_db("$database") or die ("Unable to select database.");$sqla = "SELECT * FROM `Customers` WHERE `Company` LIKE '%$customer%' ORDER BY `Company` asc";$resulta = mysql_query($sqla) or die (mysql_error ());//echo $sqla;do { printf("<tr><td><input type=\"radio\" name=\"choice\" value=%d><td> <font size=2 face=Tahoma color=blue>%s<td> <font size=2 face=Tahoma color=blue>%s<td> <font size=2 face=Tahoma color=blue>%s<td> <font size=2 face=Tahoma color=blue>%s<td> <font size=2 face=Tahoma color=blue>%s<td> </tr>", $myrowa["Customerid"], $myrowa["Company"], $myrowa["Business City"], $myrowa["Business State"], $myrowa["First Name"], $myrowa["Last Name"]); } while ($myrowa = mysql_fetch_array($resulta));?></table><input type="hidden" name="uid" value="<? echo $uid ?>" > <p><input type="submit" value="Select"><input type="hidden" name="uid" value="<? echo $uid ?>" ></form><?php}else{ showForm();}function showForm(){?><form method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>"><input type="hidden" name="uid" value="<? echo $uid ?>" ><font face="Tahoma" size="3" color="#0000FF">Type the first few alphabets of the company name.<P><font face="Tahoma" size="2" color="#0000FF">Company:<input type="text" size="12" name="customer"><input type="submit" value="Go !"></form><?php}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/5691-a-hidden-variable-not-getting-passed/ Share on other sites More sharing options...
Honoré Posted March 24, 2006 Share Posted March 24, 2006 As you use a post method for your form, try[code]$uid = $_POST["uid"];[/code] Quote Link to comment https://forums.phpfreaks.com/topic/5691-a-hidden-variable-not-getting-passed/#findComment-20287 Share on other sites More sharing options...
swatisonee Posted March 24, 2006 Author Share Posted March 24, 2006 doesn't workI need to first set $uid to the uid which appears in the address bar and $_POST doesn't contain it. that's why i needed to use $_GET but if theres a better option which will yield results, i will try itthanks Quote Link to comment https://forums.phpfreaks.com/topic/5691-a-hidden-variable-not-getting-passed/#findComment-20301 Share on other sites More sharing options...
keeB Posted March 24, 2006 Share Posted March 24, 2006 The problem is that your input tag is outside of the <form> tag.Move it inside of the <form> tag anywhere.. and it will pass through ;)Good luck Quote Link to comment https://forums.phpfreaks.com/topic/5691-a-hidden-variable-not-getting-passed/#findComment-20306 Share on other sites More sharing options...
Honoré Posted March 24, 2006 Share Posted March 24, 2006 [!--quoteo(post=357966:date=Mar 24 2006, 07:06 PM:name=swatisonee)--][div class=\'quotetop\']QUOTE(swatisonee @ Mar 24 2006, 07:06 PM) [snapback]357966[/snapback][/div][div class=\'quotemain\'][!--quotec--]doesn't workI need to first set $uid to the uid which appears in the address bar and $_POST doesn't contain it. that's why i needed to use $_GET but if theres a better option which will yield results, i will try itthanks[/quote]Try this[code]if(isset($_GET['uid'])) $uid = $_GET['uid']; else $uid = $_POST['uid'];[/code] Quote Link to comment https://forums.phpfreaks.com/topic/5691-a-hidden-variable-not-getting-passed/#findComment-20308 Share on other sites More sharing options...
keeB Posted March 24, 2006 Share Posted March 24, 2006 [!--quoteo(post=357973:date=Mar 24 2006, 05:11 PM:name=Honoré)--][div class=\'quotetop\']QUOTE(Honoré @ Mar 24 2006, 05:11 PM) [snapback]357973[/snapback][/div][div class=\'quotemain\'][!--quotec--]Try this[code]if(isset($_GET['uid'])) $uid = $_GET['uid']; else $uid = $_POST['uid'];[/code][/quote]Stop giving bad advice Quote Link to comment https://forums.phpfreaks.com/topic/5691-a-hidden-variable-not-getting-passed/#findComment-20340 Share on other sites More sharing options...
swatisonee Posted March 25, 2006 Author Share Posted March 25, 2006 keeBNo luck i'm afraid. I passed the input within both the form tags but no help at all. its like the uid doesnt have anything to do with the script, once $_GEt is run. I am at my wits end because this script is working exactly as needed but without this uid in place , i cant use it to process the remaining files !From what i can gather, once the if (isset..) part starts to work , the uid gets ignored because at that point its just searching for a value for $customer and nothing else matter...[code]$uid = $_GET["uid"];echo $uid;if(isset($_POST) && !empty($_POST["customer"])){?>[/code]Can you suggest something else i could try ? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/5691-a-hidden-variable-not-getting-passed/#findComment-20452 Share on other sites More sharing options...
kenrbnsn Posted March 25, 2006 Share Posted March 25, 2006 I think what everyone was missing is that you have two different forms being displayed. One in the main area of the code and one in a function. This is the code for the function:[code]<?phpfunction showForm(){?><form method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>"><input type="hidden" name="uid" value="<? echo $uid ?>" ><font face="Tahoma" size="3" color="#0000FF">Type the first few alphabets of the company name.<P><font face="Tahoma" size="2" color="#0000FF">Company:<input type="text" size="12" name="customer"><input type="submit" value="Go !"></form><?php}?>[/code]Here is where you're not getting the value of $uid because $uid doesn't have a value in this context. Either pass it as an arguement to the function or use the value of the $_GET superglobal array.I would use the value from the $_GET array:[code]<?phpfunction showForm(){?><form method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>"><input type="hidden" name="uid" value="<? echo $_GET['uid'] ?>" > // changed this line<font face="Tahoma" size="3" color="#0000FF">Type the first few alphabets of the company name.<P><font face="Tahoma" size="2" color="#0000FF">Company:<input type="text" size="12" name="customer"><input type="submit" value="Go !"></form><?php}?>[/code]Hope this helps.Ken Quote Link to comment https://forums.phpfreaks.com/topic/5691-a-hidden-variable-not-getting-passed/#findComment-20472 Share on other sites More sharing options...
swatisonee Posted March 25, 2006 Author Share Posted March 25, 2006 Yes it did ! Thanks Ken ! Quote Link to comment https://forums.phpfreaks.com/topic/5691-a-hidden-variable-not-getting-passed/#findComment-20508 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.