Jump to content
xisto Community
soleimanian

help me!!!!!

Recommended Posts

i used below to display my banner<?$db=mysql_connect("localhost","root","");mysql_select_db("ad",$db);$result=mysql_query("select * from ad");$row=mysql_num_rows($result);$imagenum=mysql_query("select * from ad where ID=1");while ($image=mysql_fetch_array($imagenum)) {printf("<a href='$image[1]'><img src='$image[0]' border=0 alt=wallpaper></a>");}?>it run in my pc correctly but at server display below warningWarning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in ....Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in ....

Share this post


Link to post
Share on other sites

Wow, for one, when you put it online, you're using the Online MySQL server. Your username there is not root and you do have a password. At home you probably used your own MySQL server, I'm guessing, since I see little other ways. But you need to change your connect statement so that it can connect to the host's MySQL server. Are you sure you didn't get an error about that..?

 

Change your mysql_connect to:

if(!($db=mysql_connect("localhost",$myUserName,$myPassWord)))

die("An error occured while trying to connect to the MySQL Database :" . mysql_error($db));

 

And keep in mind that you should always check for errors like this, after executing a MySQL (or any other function) statement. Don't suppose that everything always works out flawlessly. This way, at least you know where things went wrong.

 

Oh and, if you use select_db, you should select a database, not a table form a database. I'm not sure how your MySQL database works and what it's named, but it looks to me like you're using mysql_select_db to select a table, whereas you need to put your databasename in there (usually something like [username]_[databasename]).

Share this post


Link to post
Share on other sites

Oh and, if you use select_db, you should select a database, not a table form a database.

<{POST_SNAPBACK}>


He just has a database called ad.

 

 

And don't forget to put error checking in database select and queries aswell. Like lhunath said you know what caused the errors and makes fixing it a hell of a lot easier.

Share this post


Link to post
Share on other sites

You can definately use username "root" if you have root access to the MySql Server. Which means that you are using a VPS, Dedicated Server or Co-Location Server. Most VSH (Virtual Share Hosting) will not allow that.

The following code should work, if it still show an error, let me know.

<?php$db= @mysql_connect("localhost","root","rootpassword");if( !$db ) die( "Cannot Connect to Database" );@mysql_select_db("ad",$db);$imagenum = mysql_query("select * from ad where ID=1") or die(mysql_error());$imagenumcount = @mysql_num_rows($imagenum);while ($image = @mysql_fetch_object($imagenum)) {echo "<a href='".$image->imagefilename."'><img src='".$image->imagefilepath."' border=0 alt=wallpaper></a><br><br>";}?>

:)

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

<?phpmysql_select_db($database_aa, $aa);$query_Recordset1 = "SELECT * FROM xxxxx";$Recordset1 = mysql_query($query_Recordset1, $aa) or die(mysql_error());$row_Recordset1 = mysql_fetch_assoc($Recordset1);$totalRows_Recordset1 = mysql_num_rows($Recordset1);$imagenum = mysql_query("select * from ad where ID=1") or die(mysql_error());$imagenumcount = @mysql_num_rows($imagenum);while ($image = @mysql_fetch_object($imagenum)) {echo "<a href='".$image->imagefilename."'><img src='".$image->imagefilepath."' border=0 alt=wallpaper></a><br><br>";?>

Share this post


Link to post
Share on other sites

pedro, he solved the problem already, if you have a better solution, paste it, but say why you think it's worth still mentioning it now.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.