Honesty Rocks! truth rules.

Mysql Query Problems I need some help or a tutorial?

HOME      >>       Programming


I seem to be having trouble with getting my Query to post my user's ID numbers.

// Make a MySQL Connectionmysql_connect("localhost", "user", "password") or die(mysql_error());mysql_select_db("databasename") or die(mysql_error());// Retrieve all the data from the members table$result = mysql_query("SELECT * FROM members WHERE id='$id'")or die(mysql_error()); // store the record of the id table into $row$row = mysql_fetch_array( $result );// Print out the contents of the entry echo $row['id'].";

A little information about my table in my database:

table called: members
under members rows called: id, username, password, pname, cname, email, ip
under row called id: the user's information is stored.

So can someone help this fast learner on how to get the Query to run properly and actually "post" the ID# on the pages of my website?

Any help will be greatly appreciated. ^^

Notice from truefusion:
Added CODE bbcode


Since $row['id'] is an associative array element, try enclosing it inside {curly braces}.
Might work.

echo {$row['id']};
Or variations thereof. Not tested.

One other thing, do you have error_reporting enabled? Are you receiving an error message?
You are not checking to see if the query in-fact is pulling results from the database.
Does this query work using phpmyadmin?
Echo the Query to see the actual question you are asking the database.

Try this, too, after the results are added to the fetch_array:
echo '<br />';print_r($row);echo '<br />';

These are standard debugging tips and things which you can do to test that the value of the array contains valid data.


What error are you getting?

echo $row['id'].";

the ."; seems to be an opening double quote. remove that to echo $row['id']; and give that a go.


With your current PHP code there is no value for $id, so the die command is being issued and killing your script. You probably need to give $id a value. Also, next time please use the code or codebox BBCode tags when posting code.


Here is the thing. I don't get an error. It is just there is no ID# posting on the page. I have tried everything I can think of. I am fixing to check a few other things before doing some the suggestion posted here. To see if I messed something up in my coding.Thanks for the help everyone.---Concerning the BBcode and the codebox. I will try to remember the codebox next time. ^^ I was in a hurry. I had to leave for work and didn't know when the next time I would be able to get online to check this. =]


I don't get an error. It is just there is no ID# posting on the page.

The following:
SELECT * FROM members WHERE id=''

will pass as valid or true, not returning boolean false. That is why you are not receiving an error. The result is no rows were selected, therefore no echo. I do believe coolcat50 is correct with the id variable.


I finally fixed this problem. So it has been resolved. I took out the "WHERE" statement and just used "FROM members" and it posted the ID# just fine. ^^ I guess I was trying to be to specific with asking the database what I wanted.Thank you all for the help. <_<