Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
ERROR on mysql_fetch_array()
Old 08-12-2008, 05:26 PM ERROR on mysql_fetch_array()
Daman's Avatar
Extreme Talker

Posts: 157
Location: Toronto, CANADA
Trades: 0
Here is the error message:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\public_html\mysql_test.php on line 15

My local server setup:
  • Apache 2.2.9.
  • PHP 5.2.6.
  • MySQL 5
Here is the tutorial I have been following.
Everything has gone smoothly up until now.
http://www.bicubica.com/apache-php-mysql/
I am stuck on Configuring PHP to work with MySQL.

Here is the PHP used:
PHP Code:
<?php

# Define MySQL Settings
define("MYSQL_HOST""localhost");
define("MYSQL_USER""root");
define("MYSQL_PASS""password");
define("MYSQL_DB""test");

$conn mysql_connect("".MYSQL_HOST."""".MYSQL_USER."""".MYSQL_PASS."") or die(mysql_error());
mysql_select_db("".MYSQL_DB."",$conn) or die(mysql_error());

$sql "SELECT * FROM test";
$res mysql_query($sql);

while (
$field mysql_fetch_array($res))
{
$id $field['id'];
$name $field['name'];

echo 
'ID: ' $field['id'] . '<br />';
echo 
'Name: ' $field['name'] . '<br /><br />';
}

?>
Thank!
__________________

Please login or register to view this content. Registration is FREE

Solutions for online design™
Daman is offline
Reply With Quote
View Public Profile Visit Daman's homepage!
 
 
Register now for full access!
Old 08-12-2008, 09:32 PM Re: ERROR on mysql_fetch_array()
Extreme Talker

Posts: 177
Trades: 0
assuming it connects to the database correctly, that error always occurs for me when I have a table typed wrong. Make sure the table 'test' actually exists.
kbfirebreather is offline
Reply With Quote
View Public Profile
 
Old 08-13-2008, 12:05 AM Re: ERROR on mysql_fetch_array()
Daman's Avatar
Extreme Talker

Posts: 157
Location: Toronto, CANADA
Trades: 0
Checked and double checked on the db name and table name. The error is referring to line 15.

Line 15: while ($field = mysql_fetch_array($res))
__________________

Please login or register to view this content. Registration is FREE

Solutions for online design™
Daman is offline
Reply With Quote
View Public Profile Visit Daman's homepage!
 
Old 08-13-2008, 01:06 AM Re: ERROR on mysql_fetch_array()
Extreme Talker

Posts: 177
Trades: 0
change the one line to...

PHP Code:
mysql_query($sql)or die(mysql_error()); 
and see what it outputs
kbfirebreather is offline
Reply With Quote
View Public Profile
 
Old 08-13-2008, 01:13 AM Re: ERROR on mysql_fetch_array()
Daman's Avatar
Extreme Talker

Posts: 157
Location: Toronto, CANADA
Trades: 0
Interesting. I get the following message, Table 'test.test' doesn't exist
Why is it calling it "test. test"? The database name is "test".
__________________

Please login or register to view this content. Registration is FREE

Solutions for online design™
Daman is offline
Reply With Quote
View Public Profile Visit Daman's homepage!
 
Old 08-13-2008, 01:38 AM Re: ERROR on mysql_fetch_array()
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
'test.test' means 'table with name 'test' located in database with name 'test''

Using this syntax you can select data from tables located in different databases by single query (using joins), assuming that you have enough privileges to access those other databases.

Your error message shows quite clearly that a table that you try to select from does not exist. In other words, there is no table 'test' in the 'test' database.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 08-13-2008, 10:21 AM Re: ERROR on mysql_fetch_array()
Daman's Avatar
Extreme Talker

Posts: 157
Location: Toronto, CANADA
Trades: 0
Found the problem. Was selecting the wrong table name.

This...
$sql = "SELECT * FROM test";

should have been...
$sql = "SELECT * FROM name";

Thanks for all your help!
__________________

Please login or register to view this content. Registration is FREE

Solutions for online design™
Daman is offline
Reply With Quote
View Public Profile Visit Daman's homepage!
 
Reply     « Reply to ERROR on mysql_fetch_array()
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.60952 seconds with 12 queries