Lonelydreamer Posted August 17, 2004 Posted August 17, 2004 I'm trying to write a code that displays a random banner out of a data base but when I run the script I get a blank screen with no errors or anything. ><? $connection = @mysql_connect("localhost", "user", "pass") or die(error); $database = @mysql_db_select($connection, database) or die(error); $amt = @mysql_query($connection, "SELECT * FROM sites") or die(error); $amt1 = @mysql_num_rows($amt); $banner = rand(1, $amt1); $sql = "SELECT * FROM sites LIMIT $banner,1"; $result = @mysql_query($connection, $sql) or die(error); $row = mysql_fetch_array($result); $link = $row[url]; $img = $row[pic]; $out_put = "<a href=\"http://lonelydreamer.com/?page=home\"><img src=\"images/banner_top.gif\" border=0></a><br>\n"; $out_but .= "<a href=\"http://$link\"><img src=\"banners/$img\" border=0></a><br>\n"; $out_but .= "<a href=\"http://lonelydreamer.com/?page=join\"><img src=\"images/banner_bottom.gif\" border=0></a><br>\n"; print $out_put; ?> Quote
TCH-Don Posted August 18, 2004 Posted August 18, 2004 print $$out_put; ?> Is the extra $ needed Quote
Lonelydreamer Posted August 18, 2004 Author Posted August 18, 2004 I just tried that but it wasn't the only problem theres something else! Quote
Lonelydreamer Posted August 18, 2004 Author Posted August 18, 2004 Thats the thing I jsut get a blank screen. Quote
borfast Posted August 18, 2004 Posted August 18, 2004 Try putting this as the first line of your script: error_reporting(E_ALL); Then run the script again and see if it outputs some warning or error. Quote
Lonelydreamer Posted August 18, 2004 Author Posted August 18, 2004 That didn't help either but I know for sure there is a prob with the PHP and not the data base because the text out side of the PHP block I have recently added will not show either! This is what I have as of now: ><? error_reporting(E_ALL); $connection = @mysql_connect("localhost", "user", "pass") or die(mysql_error()); $database = @mysql_db_select($connection, database) or die(mysql_error()); $amt = @mysql_query($connection, "SELECT * FROM sites") or die(mysql_error()); $amt1 = @mysql_num_rows($amt); $banner = rand(1, $amt1); $sql = "SELECT * FROM sites LIMIT $banner,1"; $result = @mysql_query($connection, $sql) or die(mysql_error()); $row = @mysql_fetch_array($result); $link = $row[url]; $img = $row[pic]; $out_put = "<a href=\"http://lonelydreamer.com/?page=home\"><img src=\"images/banner_top.gif\" border=0></a><br>\n"; $out_put .= "<a href=\"http://$link\"><img src=\"banners/$img\" border=0></a><br>\n"; $out_put .= "<a href=\"http://lonelydreamer.com/?page=join\"><img src=\"images/banner_bottom.gif\" border=0></a><br>\n"; print $out_put; ?> asdfds Quote
borfast Posted August 18, 2004 Posted August 18, 2004 (edited) Well, try commenting out the whole code and add a line that outputs something. Like this: ><? error_reporting(E_ALL); // This stays here so we're sure PHP tells us about everything echo "this is inside PHP code, before everything else."; /*$connection = @mysql_connect("localhost", "user", "pass") or die(mysql_error()); $database = @mysql_db_select($connection, database) or die(mysql_error()); $amt = @mysql_query($connection, "SELECT * FROM sites") or die(mysql_error()); $amt1 = @mysql_num_rows($amt); $banner = rand(1, $amt1); $sql = "SELECT * FROM sites LIMIT $banner,1"; $result = @mysql_query($connection, $sql) or die(mysql_error()); $row = @mysql_fetch_array($result); $link = $row[url]; $img = $row[pic]; $out_put = "<a href=\"http://lonelydreamer.com/?page=home\"><img src=\"images/banner_top.gif\" border=0></a><br>\n"; $out_put .= "<a href=\"http://$link\"><img src=\"banners/$img\" border=0></a><br>\n"; $out_put .= "<a href=\"http://lonelydreamer.com/?page=join\"><img src=\"images/banner_bottom.gif\" border=0></a><br>\n"; print $out_put;*/ echo "this is inside PHP code, after everything else."; ?> asdfds This code block should work and you can work it out from here. Uncomment one line from the top and see if it still outputs both lines. Next uncomment the next line (so you'll have the two first lines of the script uncommented) and try again. ><? error_reporting(E_ALL); // This stays here so we're sure PHP tells us about everything echo "this is inside PHP code, before everything else."; $connection = @mysql_connect("localhost", "user", "pass") or die(mysql_error()); $database = @mysql_db_select($connection, database) or die(mysql_error()); /*$amt = @mysql_query($connection, "SELECT * FROM sites") or die(mysql_error()); $amt1 = @mysql_num_rows($amt); $banner = rand(1, $amt1); $sql = "SELECT * FROM sites LIMIT $banner,1"; $result = @mysql_query($connection, $sql) or die(mysql_error()); $row = @mysql_fetch_array($result); $link = $row[url]; $img = $row[pic]; $out_put = "<a href=\"http://lonelydreamer.com/?page=home\"><img src=\"images/banner_top.gif\" border=0></a><br>\n"; $out_put .= "<a href=\"http://$link\"><img src=\"banners/$img\" border=0></a><br>\n"; $out_put .= "<a href=\"http://lonelydreamer.com/?page=join\"><img src=\"images/banner_bottom.gif\" border=0></a><br>\n"; print $out_put;*/ echo "this is inside PHP code, after everything else."; ?> asdfds When it stops outputting one (or both) of the lines, you'll know you found the line that's getting you into trouble. Edited August 18, 2004 by TCH-Raul Quote
Lonelydreamer Posted August 18, 2004 Author Posted August 18, 2004 Thanks Ill get at it (time to stop playing Yetti Sports XD). If anyone happens to just see the prob please post Quote
Lonelydreamer Posted August 18, 2004 Author Posted August 18, 2004 These three lines are the ones w/ probs >$result = @mysql_query($connection, $sql) or die(mysql_error()); $amt = @mysql_query($connection, "SELECT * FROM sites") or die(mysql_error()); $database = @mysql_db_select($connection, mbgriclz_banners) or die(mysql_error()); please advise! Quote
Lonelydreamer Posted August 18, 2004 Author Posted August 18, 2004 FINALLY I FIXED IT the three lines had one thing in common the $connection variable came FIRST!!!!!! That was hours wasted.... if you wanna see the final code look below. ><? $connection = @mysql_connect("localhost", "user", "pass") or die(mysql_error() ); $db = @mysql_select_db(db, $connection) or die(mysql_error() ); $amt = @mysql_query("SELECT * FROM sites", $connection) or die(mysql_error()); $amt1 = @mysql_num_rows($amt); $amt1 = $amt1 - 1; $banner = rand(0, $amt1); $sql = "SELECT * FROM sites LIMIT $banner,1"; $result = @mysql_query($sql, $connection) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { $link = $row[url]; $img = $row[pic]; $out_put = "<center><a href=\"http://lonelydreamer.com/?page=home\"><img src=\"images/bannertop.gif\" border=0></a><br>\n"; $out_put .= "<a href=\"http://$link\"><img src=\"banners/$img\" border=0></a><br>\n"; $out_put .= "<a href=\"http://lonelydreamer.com/?page=join\"><img src=\"images/bannerbottom.gif\" border=0></a><br></center>\n"; } print $out_put; ?> Thanks for your help all!! Quote
TCH-Don Posted August 18, 2004 Posted August 18, 2004 Glad you found it. Its more satisfying when you find it yourself. Thumbs Up Quote
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.