Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Mysql Query Problems, I need some help or a tutorial?
TheChosenDarknes...
post 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. ^^

Notice from truefusion:
Added CODE bbcode
Go to the top of the page
 
+Quote Post
jlhaslip
post 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 Icon

Group: [MODERATOR]
Posts: 3,744
Joined: 24-July 05
From: In Trouble Again... still?
Member No.: 9,787
Spam Patrol



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.
Go to the top of the page
 
+Quote Post
sonesay
post Mar 16 2008, 05:11 AM
Post #3


|||[ n00b King ]|||
*********

Group: [HOSTED]
Posts: 591
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.
Go to the top of the page
 
+Quote Post
coolcat50
post 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
Spam Patrol



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.
Go to the top of the page
 
+Quote Post
TheChosenDarknes...
post 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. =]
Go to the top of the page
 
+Quote Post
truefusion
post Mar 17 2008, 04:30 AM
Post #6


Converting one Penguin at a time.
Group Icon

Group: [MODERATOR]
Posts: 1,740
Joined: 22-June 05
From: The place where moving forward means moving backwards.
Member No.: 8,528
T17 GFX Crew



QUOTE(TheChosenDarkness @ Mar 16 2008, 06:23 PM) *
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.
Go to the top of the page
 
+Quote Post
TheChosenDarknes...
post 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. smile.gif
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Testimonials(81)
  2. Maybe Someone Could Help...?(14)
  3. I Hate Dial-up Arghhhhhhh(56)
  4. Nvidia And It's No Good Firewall...(3)
  5. Import From Excel File Into Mysql Database(5)
  6. Installing Apache, Mysql, Phpmyadmin Locally(5)
  7. Can You Add Images Into A Mysql Database?(18)
  8. Creating Profiles In Php/mysql ?(7)
  9. Razr Problems(14)
  10. Geforce Fx 5200 Problems(5)
  11. Connection Problems And High Ping Playing Battlefield 2(10)
  12. Windows Vista And Its Problems(21)
  13. Problems With The Sony Ericsson S500?(6)
  14. My Problems Continue :((5)
  15. Yahoo Messenger 9.0 Is Out(1)
  1. Wireless Router Problems.(6)
  2. Problems Adding An Email Account(3)
  3. Database With Mysql++(4)
  4. Java Applet Query(1)
  5. The Best Free Php Mysql Blog(5)
  6. Mysql, Php, Apache Downloads And Setup Was A Nightmare(9)
  7. Install And Uninstall Problems(0)
  8. Yuri's Revenge Lan(0)
  9. Php And Mysql Programming(2)
  10. Best Php And Mysql Editor For Noobs(5)
  11. Span "display: _____" Problems(2)
  12. Updating Website, Ftp Problems(5)
  13. I Need Some Help With Flash And Div Overlay(4)


 



- Lo-Fi Version Time is now: 13th May 2008 - 09:52 PM