SF23103 Posted July 30, 2011 Share Posted July 30, 2011 Hey all; This script gets data from a database and displays it on a page. The page starts with header.php, then displays press_release.php, then footer.html The problem is that I can echo variables on press_release.php, but not header.php. Is it because header.php is above $f2=mysql_result($result,$i,"submission_id"); ? If I move it down I get an error: warning: mysql_numrows(): supplied argument is not a valid mysql result resource - Google Search Any ideas? :-) <?php $username="XXXXXX"; // I deleted this for the purpose of this post. $password="XXXXXXXX"; $database="XXXXXXXXX"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $id = $_GET['id']; //this gets the id from the url if($id != '' && $id > 0) { // this checks to make sure that the ID is an integer $query="SELECT * FROM ft_form_16 WHERE submission_id='$id'"; //this pulls only that id from the database include("/path/to/header.php"); } else { die (include "/path/to/templates/error.php"); //display error if ID is not an integer } /*next*/ $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); $i=0; while ($i < $num) { $f1=mysql_result($result,$i,"col_5"); $f2=mysql_result($result,$i,"submission_id"); $f3=mysql_result($result,$i,"col_1"); $f4=mysql_result($result,$i,"col_2"); $f5=mysql_result($result,$i,"submission_date"); $f6=mysql_result($result,$i,"col_4"); $f7=mysql_result($result,$i,"col_6"); $f8=mysql_result($result,$i,"col_7"); $f9=mysql_result($result,$i,"col_9"); $f10=mysql_result($result,$i,"col_10"); $f11=mysql_result($result,$i,"last_modified_date"); $f12=mysql_result($result,$i,"col_12"); $f13=mysql_result($result,$i,"col_11"); $f14=mysql_result($result,$i,"col_13"); if ($f13 == "Include") { include("/path/to/press_release.php"); } else { include("/path/to/unavailable.php"); //If "include" is checked, show the PR, otherwise show an error } $i++; } include("/path/to/full/footer.html"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/243252-not-displaying-variable/ Share on other sites More sharing options...
marcus Posted July 30, 2011 Share Posted July 30, 2011 $result = mysql_query($query) or die(mysql_error()); Error in the query will cause numrows to throw an error. Quote Link to comment https://forums.phpfreaks.com/topic/243252-not-displaying-variable/#findComment-1249312 Share on other sites More sharing options...
SF23103 Posted July 30, 2011 Author Share Posted July 30, 2011 Good call. So if I re-arrange it, it says the query is empty. That make sense because the code $id = $_GET['id']; //this gets the id from the url if($id != '' && $id > 0) { // this checks to make sure that the ID is an integer $query="SELECT * FROM ft_form_16 WHERE submission_id='$id'"; //this pulls only that id from the database include("/home/srpdv2/public_html/press/templates/full/header.php"); } else { die (include "/home/srpdv2/public_html/press/templates/error.php"); //display error if ID is not an integer } is actually what gets the data..so I can't move it below the mysql_result's. Quote Link to comment https://forums.phpfreaks.com/topic/243252-not-displaying-variable/#findComment-1249313 Share on other sites More sharing options...
marcus Posted July 30, 2011 Share Posted July 30, 2011 Ok, then put all of your code (after the die statement) into the true statement. if($id != '' && $id > 0){ // all your code that would run }else { // error } Quote Link to comment https://forums.phpfreaks.com/topic/243252-not-displaying-variable/#findComment-1249314 Share on other sites More sharing options...
SF23103 Posted July 30, 2011 Author Share Posted July 30, 2011 Duh!! Thank you so much! That's why I love this forum. An extra hundred pair of eyes always help. Worked like a charm. Quote Link to comment https://forums.phpfreaks.com/topic/243252-not-displaying-variable/#findComment-1249317 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.