MySQL Error: Warning: mysql_fetch_array(): supplied argument not valid MySQL
08-24-04, 12:09 PM
Newbie Coder
Join Date: Aug 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
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 .
08-24-04, 12:46 PM
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:
08-24-04, 12:55 PM
Newbie Coder
Join Date: Aug 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
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
08-24-04, 01:08 PM
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:
hope it helps
08-24-04, 02:32 PM
Newbie Coder
Join Date: Aug 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
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 ( $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 );
}
The file's still here:
http://www.neewah.com/zzzz/timestamp.php
PLEASE HELP ME
08-25-04, 02:01 AM
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
08-25-04, 02:56 AM
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
08-25-04, 06:34 AM
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
08-26-04, 04:39 AM
Newbie Coder
Join Date: Aug 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
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 ( $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 );
}
?>
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 .
08-26-04, 05:19 AM
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 ( $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 ); } } else { die( 'Query return no rows' ); } ?>
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off