Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[solved] php & mysql
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
midnite
Guru
Guru


Joined: 09 Apr 2006
Posts: 451
Location: Hong Kong

PostPosted: Tue Jul 11, 2006 5:14 pm    Post subject: [solved] php & mysql Reply with quote

excuse me, why i can't use the following:
Code:
<?php $abc = mysql_query('SELECT title FROM page');
echo mysql_result($abc, 2, 'title'); ?>
neither the following:
Code:
<?php $abc = mysql_query('SELECT title FROM page');
echo mysql_result($abc, 2); ?>
both don't work -.-

would anyone kindly give me a hand ?

http://hk2.php.net/manual/en/function.mysql-result.php

* oh!! sorry for my providing too little.
the error is:
Quote:
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /labz/htdocs/andy-uc/base.php on line 45

and yes, i have connected and logged in well. Functions such as mysql_fetch_array(), mysql_query(), mysql_fetch_assoc() work well around it. Sadly itself won't. i suspect it's syntax problem @.@


Last edited by midnite on Tue Jul 11, 2006 6:01 pm; edited 2 times in total
Back to top
View user's profile Send private message
mazaryk
n00b
n00b


Joined: 03 Jul 2004
Posts: 62

PostPosted: Tue Jul 11, 2006 5:22 pm    Post subject: Reply with quote

Could be many reasons, you don't give enough info.

Did you connect to the database with mysql_connect() and select a db with mysql_select_db() ?

Do you receive any error message(s)?

Do the tables exists? Can you login through the mysql command line?
_________________
http://www.mazaryk.com/
Back to top
View user's profile Send private message
basvanlola
n00b
n00b


Joined: 10 Oct 2004
Posts: 52
Location: Eefde, The Netherlands

PostPosted: Tue Jul 11, 2006 5:47 pm    Post subject: Reply with quote

I would add some error checking:
Code:

<?php
    $abc = mysql_query ( "SELECT title FROM page" );
    if ( $abc != FALSE ) {
        echo ( mysql_result ( $abc, 2 ) );
    } else {
        die ( "whoops: " . mysql_error() );
   }
?>


You should also add checks to calls to mysql_connect() and mysql_select_db() .
I always use 'error_reporting(E_ALL);' in my scripts when coding so I can see where I screwed up. Remember to remove this when going live...
_________________
Athlon-XP 2000 @ 2083MHz
Asus A7V8X-X
1 GB DDR-333 ram
nVidia Geforce FX-5500
120 GB Maxtor 6Y120P0
Back to top
View user's profile Send private message
midnite
Guru
Guru


Joined: 09 Apr 2006
Posts: 451
Location: Hong Kong

PostPosted: Tue Jul 11, 2006 6:00 pm    Post subject: Reply with quote

basvanlola wrote:
I would add some error checking:
Code:

<?php
    $abc = mysql_query ( "SELECT title FROM page" );
    if ( $abc != FALSE ) {
        echo ( mysql_result ( $abc, 2 ) );
    } else {
        die ( "whoops: " . mysql_error() );
   }
?>


You should also add checks to calls to mysql_connect() and mysql_select_db() .
I always use 'error_reporting(E_ALL);' in my scripts when coding so I can see where I screwed up. Remember to remove this when going live...


oh!! thanks very much!! you really GENIUS !!

i am such an idiot that having the line mysql_close($link); ahead.

Quote:
whoops: No database selected
Back to top
View user's profile Send private message
basvanlola
n00b
n00b


Joined: 10 Oct 2004
Posts: 52
Location: Eefde, The Netherlands

PostPosted: Tue Jul 11, 2006 6:36 pm    Post subject: Reply with quote

Quote:
Quote:
whoops: No database selected


:) Glad I could help.
_________________
Athlon-XP 2000 @ 2083MHz
Asus A7V8X-X
1 GB DDR-333 ram
nVidia Geforce FX-5500
120 GB Maxtor 6Y120P0
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum