MSQL Error not a valid MySQL result resource

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

VickedTwin
New php-forum User
New php-forum User
Posts: 3
Joined: Mon Sep 09, 2002 8:08 am

MSQL Error not a valid MySQL result resource

Postby VickedTwin » Mon Sep 09, 2002 8:13 am

Hi

Im new to Mysql and PHP programming. Im trying to get started but I cant output any data from my database. Here is some of my code

$query="select * from employees";
$result=mysql_query($query);
$array=mysql_fetch_array($result);

The bold line is bringing up the error "not a valid mysql result resource" its the same message when I use mysql_result and mysql_numrows. Im using portland as my free host could it be a php version problem? I know Im connecting to the database OK as I can create tables from php.

I really need some help as this is driving me mad

Jay

Postby Jay » Mon Sep 09, 2002 11:35 am

Your code looks fine (assuming there's only one row, then you'll need a loop), are you sure there's records in the employees table?

VickedTwin
New php-forum User
New php-forum User
Posts: 3
Joined: Mon Sep 09, 2002 8:08 am

Postby VickedTwin » Tue Sep 10, 2002 7:17 am

Yes there are 3 records in the employee table. Here is my complete code $db connects to my database.

mysql_select_db("bemexproject",$db);
$query="select * from employees where empid=1";
$result=mysql_query($query);
$array=mysql_fetch_array($result);
echo $array["lastname"];
?>

That should work according to everything Ive read, I included where empid=1 so that it will only get one record out of the table.here is the url of the page as well so you can see the error message first hand

http://www.hostultra.com/~bemexproject/test2.php

Im pulling my hair out over this

Jay

Postby Jay » Tue Sep 10, 2002 12:14 pm

Try the query in MySQL directly and see what it returns! Have you tried other queries to test the connection?

VickedTwin
New php-forum User
New php-forum User
Posts: 3
Joined: Mon Sep 09, 2002 8:08 am

Postby VickedTwin » Tue Sep 10, 2002 8:46 pm

Ill try it when I get home and post what happens, I have tried other queries to test the connection I get an error using mysql_result and I know the connection works as I can create a table using php script

serge
New php-forum User
New php-forum User
Posts: 14
Joined: Mon Sep 16, 2002 1:25 am
Location: Ukraine
Contact:

Postby serge » Mon Sep 16, 2002 1:35 am

Database was not selected, or connection was not opened, or there is no records in recordset (use mysql_num_rows($result))
------------------------
With best regards,
Serge Bulanov
AlarIT Web developer,
www.AlarIT.com


Return to “PHP coding => General”

Who is online

Users browsing this forum: Strider64 and 2 guests