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.

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

Try this instead of the echo statement:

$array = mysql_fetch_assoc($rs);
var_dump ($array);

4 Comments

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.
@user So you're saying you want to get the data from the database and compare it with user input?
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
while ($row = mysql_fetch_assoc($result)) { echo $row["Name"]; }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.