3

I want to retrieve or output data in the database but I kept on getting the error called "Resource ID".

Here is my code:

<?php 

$host="localhost";
$username="root";
$password ="123192";
$db_name = "customers";

//Connecting to your Host
mysql_connect("$host","$username","$password") or die("Failed To Connect The server");
//Selecting your Database
mysql_select_db("$db_name") or die("Failed To Select The DB");

$name = $_REQUEST['customerName'];

echo 'WELCOME! <b>'.$name.'</b> We hope that you\'ll Enjoy your stay ';

$sql="SELECT Name FROM `people` WHERE id =2 && Name = 'Kyel'";
$rs=mysql_query($sql);
echo "$rs";
?>

If I need improvement regarding my code kindly tell me.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user759630
  • 679
  • 2
  • 8
  • 11

2 Answers2

4

mysql_query() returns a resource. The to string (implicitly triggered by using echo to output it) of that is Resource ID # followed by the id.

A resource in PHP is only supposed to be used with other PHP functions. This includes but is not limited to file, curl, ftp handles, etc.

I could tell you to..

(a) use mysql_fetch_array() (or similar) or

(b) use PDO.

The latter is by far much better advice.

alex
  • 479,566
  • 201
  • 878
  • 984
0

Try this instead of the echo statement:

$array = mysql_fetch_assoc($rs);
var_dump ($array);
Len
  • 542
  • 1
  • 5
  • 11
  • it gives me an array, I only want the data itself so that I could compare it with the userinput . I'll get data from the database and then Compare it with the user input. is that even possible? I wanted to retrieve data so that I can compare it with user input. – user759630 Aug 22 '11 at 03:14
  • @user So you're saying you want to get the data from the database and compare it with user input? – Phil Aug 22 '11 at 03:22
  • Yes Precisely. that's the reason why I wanted to retrieve and get data from the database so that I can compare it with the user input – user759630 Aug 22 '11 at 03:29
  • while ($row = mysql_fetch_assoc($result)) { echo $row["Name"]; } – Len Aug 22 '11 at 03:39