|
|
|
|
![]() ![]() |
Mar 16 2008, 04:50 AM
Post
#1
|
|
|
Newbie [Level 1] ![]() Group: Members Posts: 15 Joined: 12-March 08 Member No.: 59,224 |
I seem to be having trouble with getting my Query to post my user's ID numbers.
CODE // Make a MySQL Connection mysql_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. ^^ |
|
|
|
Mar 16 2008, 05:09 AM
Post
#2
|
|
|
A computer once beat me at chess, but it was no match for me at kick boxing. ![]() Group: [MODERATOR] Posts: 3,744 Joined: 24-July 05 From: In Trouble Again... still? Member No.: 9,787 ![]() |
Since $row['id'] is an associative array element, try enclosing it inside {curly braces}.
Might work. CODE 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: CODE 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. |
|
|
|
Mar 16 2008, 05:11 AM
Post
#3
|
|
|
|||[ n00b King ]||| ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 592 Joined: 20-June 07 From: Auckland Member No.: 45,102 |
What error are you getting?
CODE echo $row['id']."; the ."; seems to be an opening double quote. remove that to echo $row['id']; and give that a go. |
|
|
|
Mar 16 2008, 05:43 AM
Post
#4
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 228 Joined: 5-October 07 From: Random Places Member No.: 51,171 ![]() |
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.
|
|
|
|
Mar 16 2008, 10:23 PM
Post
#5
|
|
|
Newbie [Level 1] ![]() Group: Members Posts: 15 Joined: 12-March 08 Member No.: 59,224 |
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. =] |
|
|
|
Mar 17 2008, 04:30 AM
Post
#6
|
|
|
Converting one Penguin at a time. ![]() Group: [MODERATOR] Posts: 1,740 Joined: 22-June 05 From: The place where moving forward means moving backwards. Member No.: 8,528 ![]() |
I don't get an error. It is just there is no ID# posting on the page. The following: SQL 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.
|
|
|
|
Mar 17 2008, 04:03 PM
Post
#7
|
|
|
Newbie [Level 1] ![]() Group: Members Posts: 15 Joined: 12-March 08 Member No.: 59,224 |
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. |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 14th May 2008 - 12:24 AM |