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
Old 06-24-2005, 09:19 PM Mysql query problems
bman's Avatar
Skilled Talker

Posts: 85
Location: USA
Trades: 0
Can some one help me out here?

I am receiving the following error when I run my script to connect and return simple results for my dB.

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\inetpub\wwwroot\sites\mapq1.PHP on line 77

Error line (77) is marked in red below.
Code:
//connect to the database server
$connection = mysql_connect($db_host, $db_username, $db_password) or die(mysql_error());

//select database
$db = mysql_select_db($db_name, $connection);



$sql="select regid,firstname from users";

$rs=mysql_query ($sql, $connection);

while( $row = mysql_fetch_array($rs) )		{
			echo("user: ".$row["regid"]);
			echo("-First Name: ".$rown["firstname"]."<br>");
		}
?>

</body>
</html>
Can anyone see what I am doing wrong?
bman is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-24-2005, 09:55 PM
Republikin's Avatar
Defies a Status

Posts: 3,189
Trades: 3
This...

PHP Code:
$rs=mysql_query ($sql$connection); 
With the space is invalid although I don't see why it did not throw a parse error first. Try removing the space though and let me know if that worked.
__________________

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
Republikin is offline
Reply With Quote
View Public Profile
 
Old 06-24-2005, 10:10 PM
Anacrusis's Avatar
Defies a Status

Posts: 2,099
Name: Adam
Location: Colchester CT
Trades: 0
I don't think the space matters as PHP removes all spaces before the code is parsed.

You should be checking for errors everytime you issue a statement against the database. I've rewritten your code to include error checking.

PHP Code:
//connect to the database server
$connection mysql_connect($db_host$db_username$db_password) or die(mysql_error());

//select database
$db mysql_select_db($db_name$connection) or die (mysql_error());



$sql="select regid,firstname from users";

$rs=mysql_query ($sql$connection);
if (!
$rs) die ("ERROR: "mysql_error());


while( 
$row mysql_fetch_array($rs) ){
echo(
"user: ".$row["regid"]);
echo(
"-First Name: ".$rown["firstname"]."<br>");
}
?>

</body>
</html> 
Anacrusis is offline
Reply With Quote
View Public Profile
 
Old 06-24-2005, 10:39 PM
celticbrue's Avatar
Extreme Talker

Posts: 175
Location: Wiltshire, England
Trades: 0
Hi,

I think this will sort it, CHANGE THIS: -
PHP Code:
while( $row mysql_fetch_array($rs) ){ 
echo(
"user: ".$row["regid"]); 
echo(
"-First Name: ".$rown["firstname"]."<br>"); 

TO THIS
PHP Code:
while( $row mysql_fetch_array($rs) ){ 
echo(
"user: ".$row["regid"]); 
echo(
"-First Name: ".$row["firstname"]."<br>"); 

Note the change to the second echo statement in the while loop, $rown has not been defined which will cause the error you are getting.

Hope it works.

Ian
__________________
Found this useful? - HIT MY TALKUPATION!


Please login or register to view this content. Registration is FREE
celticbrue is offline
Reply With Quote
View Public Profile
 
Old 06-24-2005, 11:12 PM
Republikin's Avatar
Defies a Status

Posts: 3,189
Trades: 3
This error....

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\inetpub\wwwroot\sites\mapq1.PHP on line 77

Definatly means that there is an error with either the query itself, it could also be that your SQL itself is invalid.
__________________

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
Republikin is offline
Reply With Quote
View Public Profile
 
Old 06-25-2005, 12:16 AM
bman's Avatar
Skilled Talker

Posts: 85
Location: USA
Trades: 0
Thanks for the help. I do believe it helped. But I found that the dB had errors as well. But I got them fixed so thanks again
bman is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Mysql query problems
 

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.24046 seconds with 12 queries