Jump to content

Recommended Posts

Posted

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;
?>

Posted

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.

Posted

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

Posted (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 by TCH-Raul
Posted

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!

Posted

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!!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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...