Jump to content


Photo

Variable posting problem


  • Please log in to reply
6 replies to this topic

#1 JDPerry

JDPerry
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 19 April 2006 - 02:48 PM

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.

#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 19 April 2006 - 02:55 PM

Try to change this:

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

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

#3 JDPerry

JDPerry
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 19 April 2006 - 05:38 PM

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

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

Extract($result);
$EmpNum = $result;
}
To this:
while ($row = mysql_fetch_array($result)){
   $EmpNum = $row['EmpNum']; // Or whatever the field's name is.
}
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?

#4 Dobakat

Dobakat
  • Members
  • PipPipPip
  • Advanced Member
  • 54 posts

Posted 19 April 2006 - 05:49 PM

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

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


#5 JDPerry

JDPerry
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 19 April 2006 - 06:36 PM

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

it should be:
$link = mysql_connect ('hosthost','database_name','password') OR die('problem w/ link');
[/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.

#6 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 19 April 2006 - 06:39 PM

Does it actually outputs your variable? I mean, when you open your page, what exactly you see

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

?
~ D Kuang

#7 JDPerry

JDPerry
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 19 April 2006 - 07:20 PM

[!--quoteo(post=366543:date=Apr 19 2006, 01:39 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ Apr 19 2006, 01:39 PM) View Post[/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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users