Forum Moderators: coopster

Message Too Old, No Replies

php/mysql errors on new host

but works fine on old

         

chrisandsarah

5:02 pm on Jun 11, 2003 (gmt 0)

10+ Year Member



Hi
I'm new to php/mysql, but ive just about got the hang of understanding and tailoring bits of code aslong as its simple bits!

Someone else kindly built a database for one of my sites and provided me with the php etc and it works great on there.

To enable me to play around with it, ive just signed up and got a new host and domain, uploaded the mysql database and scripts (just one php file) and changed my username/password/databaseName etc

but when i go to load the index.php file, i get error messages at the top of the page. the page loads but not properly.
I just wondered, is all mysql/php compatible from host to host?

These are the errors i get at top of page:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/username/public_html/widgets/functions.php on line 102

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/username/public_html/widgets/functions.php on line 103

many thanks, chris

jaski

5:16 pm on Jun 11, 2003 (gmt 0)

10+ Year Member



The mysql hostname, username and password could be different on the new machine .. you may need to update those in your php script.

chrisandsarah

5:25 pm on Jun 11, 2003 (gmt 0)

10+ Year Member



Yes, my hostname,username,password is different, but i changed it and it connects to the db so i dont think its that.

Could it be anything to do with i'm using a temporary website address until my domain becomes active?
e.g [wwwtempdomain.net...]

jaski

5:31 pm on Jun 11, 2003 (gmt 0)

10+ Year Member



>>supplied argument is not a valid MySQL result resource

This error comes when your query fails to execute

try adding this line after your line 102 (where error comes)

echo mysql_error();

it should display an error message on the screen .. which can give some clue.

..temporary site should not be any problem.

daisho

8:27 pm on Jun 11, 2003 (gmt 0)

10+ Year Member



You should also confirm that mysql_connect succeeded. If you do not test for errors until you run your SQL then you don't know where your error is.

Test for an error after mysql_connect, mysql_select_db, mysql_query and mysql_fetch_array.

As soon as you get an error run mysql_error() which will give you a better description of the problem.

daisho

chrisandsarah

10:14 pm on Jun 11, 2003 (gmt 0)

10+ Year Member



I did as you said and it comes up with this at top of page:

Access denied for user: 'user_name@localhost' to database 'my_database'

ive checked my username,password, database name etc a dozen times and they are all correct. i cant figure out why it denies access

Birdman

10:23 pm on Jun 11, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do you have phpMyAdmin on this host?

chrisandsarah

10:27 pm on Jun 11, 2003 (gmt 0)

10+ Year Member



Yes i do

Birdman

10:34 pm on Jun 11, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just copy the connection string they give(hopefully) you to the page and then, in your script, add a line to echo your SQL query, right after you defined it.

$sql = "SELECT ....";
echo $sql;
$row = mysql_query($sql);

Then copy/paste the output into phpMyAdmin.

Also, look for missing vars.

Birdman

10:43 pm on Jun 11, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It is possible that you need to call the variables like this:

$_GET['location']

See Predefined Variables [php.net].

grahamstewart

11:02 pm on Jun 11, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hang on BirdMan I think your getting ahead of yourself.
ChrisSarah says he/she gets 'access denied' when they try to connect so lets start there.

There are 3 things needed to use the mysql_connect() function in PHP. They are:

  • the address of the database - the server (and possibly port) that it is running on. Judging by you error message this is currently set to 'localhost' which hould work if the database is on the same machine as the web server (pretty common).

  • your username - is the one reported in the error message your correct user name?

  • your password - usually the error message says "Access denied for user: 'user_name@localhost' (using password: YES)" so perhaps your password is not being sent?
  • chrisandsarah

    11:06 pm on Jun 11, 2003 (gmt 0)

    10+ Year Member



    Ive managed to connect now without errors. thanks.
    Got a new problem though which i'll tackle tomorrow. its getting late.
    thanks for all youtr help

    chrisandsarah

    11:24 pm on Jun 11, 2003 (gmt 0)

    10+ Year Member



    it was my username which was the problem.(sorry!)

    My host adds an underscore automatically (dont know why?)to any database name i create and also adds one to the front of my user name when i create one.

    but in my php file only my database name required the underscore and not the username, e.g
    mysql_select_db ("hostputthis_icalleditthis");

    thanks again for all your help