Jump to content

Recommended Posts

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 work

Thanks
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>

<?php


mysql_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]
Link to comment
https://forums.phpfreaks.com/topic/5691-a-hidden-variable-not-getting-passed/
Share on other sites

[!--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 work

I 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 it

thanks
[/quote]
Try this
[code]
if(isset($_GET['uid'])) $uid = $_GET['uid']; else $uid = $_POST['uid'];
[/code]
[!--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
keeB

No 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.
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]<?php
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]
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]<?php
function 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
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.