Jump to content

Variable posting problem


JDPerry

Recommended Posts

I am using the code below to try and pass a variable to the next page. It is the second part of an IF statement. I am sure that my connection to the database is correct and that the post variable from the previous page is available I think the way I have constructed my query, or the way I am trying to pass it is not correct. My code is listed below:

echo "<form action = 'report_module.php' METHOD = 'POST'>";
echo "<table align 'center'>";
echo "<tr>";
echo "<td>";
$link = mysql_connect(hosthost','database_name','password') OR die('problem w/ link');
mysql_select_db('fareport_far') or die('could not select database');
$query = "SELECT * FROM UserInfo WHERE EmpID = '{$HTTP_POST_VARS['EmpID']}'";
$result = mysql_query($query) or die('query2 failed'.mysql_error());
$row = mysql_fetch_array($result);

while($row = mysql_fetch_array($result)){

Extract($result);
$EmpNum = $result;
}
mysql_close($link);
echo "</tr>";
echo "</td>";
echo "<tr>";
echo "<td>";
print ("<INPUT TYPE=\"hidden\" NAME=\"EmpNum\"
VALUE=\"$EmpNum\">\n");
echo "<INPUT TYPE='submit' VALUE='View Faculty Report'>";
echo "</tr>";
echo "</td>";
echo "</table>";
echo "</form>";

Any help would be greatly appreciated.
Link to comment
Share on other sites

Try to change this:

[code]while($row = mysql_fetch_array($result)){

Extract($result);
$EmpNum = $result;
}[/code]
To this:
[code]while ($row = mysql_fetch_array($result)){
   $EmpNum = $row['EmpNum']; // Or whatever the field's name is.
}[/code]
Obviously $EmpNum will be the last row's value if there is more than 1 row retrieved.
Link to comment
Share on other sites

[!--quoteo(post=366444:date=Apr 19 2006, 09:55 AM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ Apr 19 2006, 09:55 AM) [snapback]366444[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Try to change this:

[code]while($row = mysql_fetch_array($result)){

Extract($result);
$EmpNum = $result;
}[/code]
To this:
[code]while ($row = mysql_fetch_array($result)){
   $EmpNum = $row['EmpNum']; // Or whatever the field's name is.
}[/code]
Obviously $EmpNum will be the last row's value if there is more than 1 row retrieved.
[/quote]


I tried changing that to your suggestion but it didn't work. It pass the variable name "EmpNum" but the value is always blank. I have some other variable on the page that seem to post properly but for some reason that one will not. Short of my query find no results do you have any other suggestions?
Link to comment
Share on other sites

well i am not sure if you were aware or not, but there is a ' missing in:
[code]
$link = mysql_connect (hosthost','database_name','password') OR die('problem w/ link');
[/code]

it should be:
[code]
$link = mysql_connect ('hosthost','database_name','password') OR die('problem w/ link');
[/code]
Link to comment
Share on other sites

[!--quoteo(post=366517:date=Apr 19 2006, 12:49 PM:name=Dobakat)--][div class=\'quotetop\']QUOTE(Dobakat @ Apr 19 2006, 12:49 PM) [snapback]366517[/snapback][/div][div class=\'quotemain\'][!--quotec--]
well i am not sure if you were aware or not, but there is a ' missing in:
[code]
$link = mysql_connect (hosthost','database_name','password') OR die('problem w/ link');
[/code]

it should be:
[code]
$link = mysql_connect ('hosthost','database_name','password') OR die('problem w/ link');
[/code]
[/quote]


Those are actually just generic, I was afraid to post the actual info on the web. Do you have any other suggestions as to why the variable would be blank. I am struggling to see what I am doing wrong.
Link to comment
Share on other sites

[!--quoteo(post=366543:date=Apr 19 2006, 01:39 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ Apr 19 2006, 01:39 PM) [snapback]366543[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Does it actually outputs your variable? I mean, when you open your page, what exactly you see

<INPUT TYPE="hidden" NAME="EmpNum" VALUE="**HERE**">

?
[/quote]


There are other variables that are passed, I only reference the one I am having problems with. One the receivng page I put a loop to display the passed values so I could check them over and it shows the following:

EmpNum,
EmpID, JSmith
PeriodID, 2

For some reason it always display as a blank. The EmpID, and PeriodID are post variables that I just carry over from the previous page, the EmpNum I am trying to get through the query.
Link to comment
Share on other sites

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.