Current location: Hot Scripts Forums » Programming Languages » PHP » MySQL Error: Warning: mysql_fetch_array(): supplied argument not valid MySQL


MySQL Error: Warning: mysql_fetch_array(): supplied argument not valid MySQL

Reply
  #1 (permalink)  
Old 08-24-04, 12:09 PM
zibykid zibykid is offline
Newbie Coder
 
Join Date: Aug 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Question MySQL Error: Warning: mysql_fetch_array(): supplied argument not valid MySQL

Hi,
When using this script, i got a funny sorta error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/neewah9/public_html/zzzz/timestamp.php on line 21

#EDIT# Also, I'm using PHP 4.5 or 4.6???

Line 21 is: while ( $row = mysql_fetch_array( $rs ) )

and the whole script (trying to display the servers current time):


$conn = mysql_connect( "localhost", "root" );

$rs = mysql_select_db( "my_database", $conn );

$sql = "select * from guestbook where id=1";

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

#split the timestamp into organized date format
while ( $row = mysql_fetch_array( $rs ) )
{
$datetime = $row["time"];
$year = substr( $datetime, 0, 4 );
$mon = substr( $datetime, 4, 2 );
$day = substr( $datetime, 6, 2 );
$hour = substr( $datetime, 8, 2 );
$min = substr( $datetime, 10, 2 );
$sec = substr( $datetime, 12, 2 );
$orgdate = date("l F dS, Y h:i A", mktime( $hour, $min, $sec, $mon, $day, $year ) );
echo( "Time of entry: " . $orgdate );
}


Can you help at all?
Thanks a lot, ZibyKid
---
NeewaH!
PHP CSSEditor

Last edited by zibykid; 08-24-04 at 12:15 PM.
Reply With Quote
  #2 (permalink)  
Old 08-24-04, 12:46 PM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by zibykid
$sql = "select * from guestbook where id=1";
that is the error.. should be like this:
Code:
$sql = "select * from guestbook where id='1'";
Reply With Quote
  #3 (permalink)  
Old 08-24-04, 12:55 PM
zibykid zibykid is offline
Newbie Coder
 
Join Date: Aug 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy

Thanks, I've edited it but i've still got the same error.
Here's the URL for the php: http://www.neewah.com/zzzz/timestamp.php
Reply With Quote
  #4 (permalink)  
Old 08-24-04, 01:08 PM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
oh.. btw.. your missing a parameter in your connection.. the password.. and you never execute the connection or db select
try this:
PHP Code:

$conn mysql_connect'localhost''root''') or die("can\'t connect"); 

$db mysql_select_db("my_database") or die("can\'t select database");

$rs mysql_query("select * from guestbook where id='1'");

#split the timestamp into organized date format 
while ( $row mysql_fetch_array$rs ) ) { 
hope it helps
Reply With Quote
  #5 (permalink)  
Old 08-24-04, 02:32 PM
zibykid zibykid is offline
Newbie Coder
 
Join Date: Aug 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy

Thanks 4 trying but now I get a Parse error: unexpected $ in /home/neewah9/public_html/zzzz/timestamp.php on line 33

Lets start again...
Here's all of the PHP code:

PHP Code:

$conn mysql_connect'localhost''root''') or die("can\'t connect"); 

$db mysql_select_db("my_database") or die("can\'t select database"); 

$rs mysql_query("select * from guestbook where id='1'"); 

#split the timestamp into organized date format 
while ( $row mysql_fetch_array$rs ) ) { 

  {
    
$datetime $row["time"];
    
$year substr$datetime0);
    
$mon  substr$datetime4);
    
$day  substr$datetime6);
    
$hour substr$datetime8);
    
$min  substr$datetime10);
    
$sec  substr$datetime12);
    
$orgdate date("l F dS, Y h:i A"mktime$hour$min$sec$mon$day$year ) );
    echo( 
"Time of entry: " $orgdate );
  } 
The file's still here:
http://www.neewah.com/zzzz/timestamp.php

PLEASE HELP ME
Reply With Quote
  #6 (permalink)  
Old 08-25-04, 02:01 AM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by zibykid
while ( $row = mysql_fetch_array( $rs ) ) {

{
$datetime = $row["time"];
unexpected $ becourse you have 2* '{' after while.. delete one of them
Reply With Quote
  #7 (permalink)  
Old 08-25-04, 02:56 AM
gorrilla gorrilla is offline
Newbie Coder
 
Join Date: Jan 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
$conn = mysql_connect( "localhost", "root" );

like wille said, you need a third password parameter in there..it goes in the form of:

mysql_connect( host, username, password );

so if "root" is your username to the db, then u need to have the third parameter as your password..like so:

$conn = mysql_connect( "localhost", "root", "mypassword" );

hope that helps
Reply With Quote
  #8 (permalink)  
Old 08-25-04, 06:34 AM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by gorrilla
$conn = mysql_connect( "localhost", "root" );

like wille said, you need a third password parameter in there..it goes in the form of:

mysql_connect( host, username, password );

so if "root" is your username to the db, then u need to have the third parameter as your password..like so:

$conn = mysql_connect( "localhost", "root", "mypassword" );

hope that helps
if you look at zibykid last post (#5) you see that he has the third argument there
Reply With Quote
  #9 (permalink)  
Old 08-26-04, 04:39 AM
zibykid zibykid is offline
Newbie Coder
 
Join Date: Aug 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy

What on earth is wrong with this????

PHP Code:

<?php

$conn 
mysql_connect'localhost''root''') or die("can't connect"); 
$db mysql_select_db("neewah9_bingo") or die("can't select database"); 

$rs mysql_query("select * from guestbook where id='1'"); 

#split the timestamp into organized date format 
while ( $row mysql_fetch_array$rs ) ) 

  {
    
$datetime $row["time"];
    
$year substr$datetime0);
    
$mon  substr$datetime4);
    
$day  substr$datetime6);
    
$hour substr$datetime8);
    
$min  substr$datetime10);
    
$sec  substr$datetime12);
    
$orgdate date("l F dS, Y h:i A"mktime$hour$min$sec$mon$day$year ) );
    echo( 
"Time of entry: " $orgdate );
  }

?>
I get that error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/neewah9/public_html/zzzz/timestamp.php on line 15

PLEASE HELP!!!!!!!!

Last edited by zibykid; 08-26-04 at 04:51 AM.
Reply With Quote
  #10 (permalink)  
Old 08-26-04, 05:19 AM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
try:
PHP Code:

<?php 
$conn 
mysql_connect'localhost''root''') or die("can't connect"); 
$db mysql_select_db("neewah9_bingo") or die("can't select database"); 
$rs mysql_query("select * from guestbook where id='1'") or die('Error in query: '.mysql_error()); 
$n mysql_num_rows($rs);
#split the timestamp into organized date format 
if ($n != 0) {
 while ( 
$row mysql_fetch_array$rs )) { 
     
$datetime $row["time"]; 
     
$year substr$datetime0); 
     
$mon  substr$datetime4); 
     
$day  substr$datetime6); 
     
$hour substr$datetime8); 
     
$min  substr$datetime10); 
     
$sec  substr$datetime12); 
     
$orgdate date("l F dS, Y h:i A"mktime$hour$min$sec$mon$day$year ) ); 
     echo( 
"Time of entry: " $orgdate ); 
 }
} else {
 die(
'Query return no rows');
}
?>
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 02:22 AM
NEED HELP - Warning: mysql_fetch_array(): supplied argument is not a valid MySQL r ArgonX PHP 4 08-19-04 01:59 PM
mysql_fetch_array(): supplied argument is not a valid MySQL result resource... Dion PHP 3 07-16-04 03:48 AM
Supplied argument is not a valid MySQL result resource help aequo PHP 2 06-15-04 08:13 AM
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result ... hukka PHP 1 01-12-04 12:16 AM


All times are GMT -5. The time now is 04:24 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.