Hi there, for the life of me I can't work out what is wrong with this script, but when it runs I get this message.

Warning: mysql_error(): supplied argument is not a valid MySQL-Link resource in....

<?

$q6 = "select * from banners where lang = \"$_SESSION[lang]\" and section = \"top\" ORDER BY RAND() limit 1"; 

$r6 = mysql_query($q6) or die(mysql_error(Error5));

while($a6 = mysql_fetch_array( $r6 )) 

{ 

echo "$a6[content]";

}

?>

If anyone can help it would be greatly appreciated.

have you done a mysql_connect()?

have you done a mysql_connect()?

Hi, yes I have a mysql_connect() it's part of a much larger script, but this is the section it says it has a problem with.

Thanks for your help though.

Try this:

$q6 = "SELECT * FROM banners WHERE lang='{$_SESSION['lang']}' AND section='top' ORDER BY RAND() LIMIT 1";

Please check if this works:

$lang = $_SESSION['lang'];

$q6 = sprintf("SELECT * FROM banners WHERE lang='%s' AND section='top' ORDER BY RAND() LIMIT 1",mysql_real_escape_string($lang));
commented: What can I say. It solved my problem. Thanks +1

That fixed the problem. Thank you very much for your help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.