Error: "Resource id #3"
Hello,
I'm starting to learn how to manage databases with
MySQL/PHP. The program is very basic but I have a
strange error: "Resource id #3".
I read many things on Internet and understood that
others have this error because they are trying to echo
the pointer of the query and not the result itself.
It's not my case so I don't understand.
Thank you very much for your help.
<?
/*This program will log on to a users DB to check if
the user is allowed to log in or not.
The program checks the login and password of the user.
*/
$login="";
if (isset($_POST['login'])) {
$login=$_POST['login'];
}
if (isset($_POST['password'])) {
$password=$_POST['password'];
}
//log to the server
$db=mysql_connect("localhost","root","");
if ($db) {
//test if the connexion works
$sel=mysql_select_db("test");
if ($sel) {
$sql_query="SELECT * FROM mytable WHERE
login='$login'";
$result=mysql_query($sql_query);
if ($result) {
//check if there is a result
echo $result;
}
//the query didn't work
else echo mysql_error();
}
else echo mysql_error();
}
?>
____________________________________________________________ ______
Découvrez le nouveau Yahoo! Mail : 250 Mo d'espace de stockage pour vos mails !
Créez votre Yahoo! Mail sur http://fr.mail.yahoo.com/
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Error: "Resource id #3"
The message that you receive is not an error, it
is a description of the object $result after the
query is done.
So, you will not get anywhere just by echo $result,
you have to process that information using one
of the mysql_fetch_array(),mysql_fetch_assoc(),
mysql_result().
In your case try :
....
if ($result) { =09
//check if there is a result
//echo $result;
$row=3Dmysql_fetch_assoc($result);
var_dump($row); // to see the exact structure
// and you can you the array like
echo $row["password"]; //or what the column name is
}
....
Hope it helps,
capi
On Sat, 2005-05-14 at 12:16 +0200, Marc Henri wrote:
> Hello,
>
> I'm starting to learn how to manage databases with
> MySQL/PHP. The program is very basic but I have a
> strange error: "Resource id #3".
> I read many things on Internet and understood that
> others have this error because they are trying to echo
> the pointer of the query and not the result itself.
> It's not my case so I don't understand.
>
> Thank you very much for your help.
>
> <?
> /*This program will log on to a users DB to check if
> the user is allowed to log in or not.
> The program checks the login and password of the user.
> */
> $login=3D"";
> if (isset($_POST['login'])) {
> $login=3D$_POST['login'];
> }
> if (isset($_POST['password'])) {
> $password=3D$_POST['password'];
> }
>
> //log to the server
> $db=3Dmysql_connect("localhost","root","");
> if ($db) {
> //test if the connexion works
> $sel=3Dmysql_select_db("test");
> if ($sel) {
> $sql_query=3D"SELECT * FROM mytable WHERE
> login=3D'$login'";
> $result=3Dmysql_query($sql_query);
> if ($result) {
> //check if there is a result
> echo $result;
> }
> //the query didn't work
> else echo mysql_error();
> }
> else echo mysql_error();
> }
> ?>
>
>
>
> =09
>
> =09
> =09
> ____________________________________________________________ ______
> D=C3=A9couvrez le nouveau Yahoo! Mail : 250 Mo d'espace de stockage pour =
vos mails !
> Cr=C3=A9ez votre Yahoo! Mail sur http://fr.mail.yahoo.com/
>
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
RE: Error: "Resource id #3"
Actually, that is exactly what you are doing. $result is the handle to the
dataset, not the dataset itself. Try this:
//log to the server
$db=mysql_connect("localhost","root","");
if ($db) {
//test if the connexion works
$sel=mysql_select_db("test");
if ($sel) {
$sql_query="SELECT * FROM mytable WHERE
login='$login'";
$result=mysql_query($sql_query);
if ($result) {
//check if there is a result
$rows = mysql_fetch_array($result)
foreach ($rows as $key => $value)
{
echo $key . " :: ". $value;
}
}
//the query didn't work
else echo mysql_error();
}
else echo mysql_error();
}
Bastien
>From: Marc Henri <marchenri1 [at] yahoo.fr>
>To: php-db [at] lists.php.net
>Subject: [PHP-DB] Error: "Resource id #3"
>Date: Sat, 14 May 2005 12:16:58 +0200 (CEST)
>
>Hello,
>
>I'm starting to learn how to manage databases with
>MySQL/PHP. The program is very basic but I have a
>strange error: "Resource id #3".
>I read many things on Internet and understood that
>others have this error because they are trying to echo
>the pointer of the query and not the result itself.
>It's not my case so I don't understand.
>
>Thank you very much for your help.
>
><?
>/*This program will log on to a users DB to check if
>the user is allowed to log in or not.
>The program checks the login and password of the user.
>*/
>$login="";
>if (isset($_POST['login'])) {
> $login=$_POST['login'];
> }
>if (isset($_POST['password'])) {
> $password=$_POST['password'];
> }
>
>//log to the server
>$db=mysql_connect("localhost","root","");
>if ($db) {
>//test if the connexion works
> $sel=mysql_select_db("test");
> if ($sel) {
> $sql_query="SELECT * FROM mytable WHERE
>login='$login'";
> $result=mysql_query($sql_query);
> if ($result) {
> //check if there is a result
> echo $result;
> }
> //the query didn't work
> else echo mysql_error();
> }
>else echo mysql_error();
>}
>?>
>
>
>
>
>
>
>
>___________________________________________________________ _______
>Découvrez le nouveau Yahoo! Mail : 250 Mo d'espace de stockage pour vos
>mails !
>Créez votre Yahoo! Mail sur http://fr.mail.yahoo.com/
>
>--
>PHP Database Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php
>
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
RE: Error: "Resource id #3"
Hello,
Thank you very much to Bastien Koert and Firan
Corneliu. You both solved my problem.
Shame on me!
____________________________________________________________ _________________
Découvrez le nouveau Yahoo! Mail : 1 Go d'espace de stockage pour vos mails, photos et vidéos !
Créez votre Yahoo! Mail sur http://fr.mail.yahoo.com
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php