JDPerry Posted April 19, 2006 Share Posted April 19, 2006 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. Quote Link to comment Share on other sites More sharing options...
poirot Posted April 19, 2006 Share Posted April 19, 2006 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 Link to comment Share on other sites More sharing options...
JDPerry Posted April 19, 2006 Author Share Posted April 19, 2006 [!--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? Quote Link to comment Share on other sites More sharing options...
Dobakat Posted April 19, 2006 Share Posted April 19, 2006 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 Link to comment Share on other sites More sharing options...
JDPerry Posted April 19, 2006 Author Share Posted April 19, 2006 [!--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. Quote Link to comment Share on other sites More sharing options...
poirot Posted April 19, 2006 Share Posted April 19, 2006 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 Link to comment Share on other sites More sharing options...
JDPerry Posted April 19, 2006 Author Share Posted April 19, 2006 [!--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, JSmithPeriodID, 2For 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. Quote Link to comment 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.