Jul 26, 2008

Mysql Query Problems - I need some help or a tutorial?

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Database

free web hosting

Mysql Query Problems - I need some help or a tutorial?

TheChosenDarkness
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

 

 

 


Reply

jlhaslip
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.

Reply

sonesay
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.

Reply

coolcat50
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.

Reply

TheChosenDarkness
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. =]

Reply

truefusion
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.

Reply

TheChosenDarkness
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

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : mysql query problems

  1. Database With Mysql++ - getting mySQL++ to work with trap17 (7)
    Hi, I'm trying to build an online game and figured the easiest way to do the server list would
    be to make a mySQL database for it; however, I use the con() command on the IP i get from pinging my
    website and I always get an abnormal program termination; however, it will work with the mySQL on my
    own machine. The code is below: CODE #include <iostream> #include <iomanip>
    #include <mysql++> #include "pass.h"//holds my password (i program at
    school) int main(void) {     Connection con("t3jem3_test","...
  2. Mysql-essential-5.0.51 Installion Problem - please help me.(urgent) (2)
    Dear friend, please help me. Iam working on php project (matchmaking site). I have downloaded mysql
    essensial 5.0.51. When i was installing mysql 5.0.51, i got following error - Error 1901: Error
    attempting to read from the source installation database:
    c:\windows\installer\527ec6.msi What is solution of this problem ? Iam using
    windows xp professional version 2002 (service pack 2). Please post your reply. Iam waiting for your
    answer. ...
  3. Problems With Apache Alias - I want to install RPG Web Profiler (0)
  4. The Best Free Php Mysql Blog - any idea (5)
    Hi everyone Recently i tried to upload a personal blog. as I know a bit of PHP programming I was
    looking for a free open source PHP blog. first I tried Wordpress out but there was few problems
    that i needed to change php.ini or .htaccess file and also some other PHP settings. as i was trying
    it out on a free web host i didn't have access to php.ini. so i have changed it from Wordpress
    to bblog , i have installed it successfully and i followed it's safety instruction (deleting
    install folder and install.php and CHmod config.php )then i got another problem i ...
  5. Mysql - (7)
    Hi... One of my hosts hasnīt MySQL but i need to develop a login system so I need to know if itīs
    possible to use a MySQL database intalled in another host... If itīs possible can you explain me how
    to do it? Thanks in advance...
  6. Loading File Into Blob Fields To Mysql - (1)
    Hi all! does any know how to load file into blob filed by sql script?...
  7. Mysql Datatype Int() Question - Not sure what value to use inside int() (1)
    Can anyone clarify what the value in int() actually does? CREATE TABLE job_class ( jc_id int(1)
    NOT NULL AUTO_INCREMENT PRIMARY KEY, jc_index int(2) NOT NULL, jc_name varchar(20) NOT NULL, jc_type
    varchar(20) NOT NULL ); I was under the impression that any integer value used inside a () was
    the limit that data-type would have. In the PRIMARY KEY column I was able to add integer values
    1-18. I'm kinda confused now If I can add 2 digit integers there then what is the point of
    assigning values inside brackets() For the varchar() any number put in there does limit...
  8. Mysql And Sql - difference??? (7)
    I was wondering what is the difference between MySQL and SQL. I was really confused when i planned
    to do a project recently. This question has haunted me for a long time. Is it both same?...
  9. Installing Mysql On Unix, Linux - (2)
    Download the latest version of MySQL.Choose the latest stable release and, from the stable release
    page, choose the option under "Source Downloads" marked "tarball (.tar.gz)". Download the file into
    a directory where files can be created and there is sufficient disk space. A good location is /tmp.
    Change directory to this location using: 1. % cd /tmp Note that the % character
    should not be typed in; this represents the Linux shell prompt and indicates that the command should
    be entered at the shell prompt. 2. Uncompress the package in the new ...
  10. Mysql Database Copying - (4)
    Is there anyway to merge 2 databases? I have an XOOPS and SMF both installed with Fantastico, and
    the bridge is not working like the Joomla! one does. (with the seperate db capability) i know
    how to transfer all the tables by hand but depending on how much data you have stored in mysql could
    take a long time. Take short time!? Help me!...
  11. Exporting Database Problems - (3)
    On the host I moved here from, I have a database that I would like to transfer. On this host I am
    unable to use PHPMyAdmin, but I have MySQL-Admin 3.3 that works fine. But the main problem is the
    host. Recently they made it so you there is only a 1mb upload limit, and also that MySQL temporarily
    will not operate properly. Which is basically why I want to get off that host. Anyway, I can export
    each of the small tables easily. But I have tables that are over 2mb, and I do not know how I can
    get them. When I click on "Show table", the table starts to load, but then it sto...
  12. Sqlserver 2005 - Login Problems - (0)
    Hi guys, I just installed sqlserver2005 and when i open server management studio and try to connect
    I chose SQL server authentication mode it then asks me for a login and password. I have no idea what
    this is. Is there a default? or do i need to add a login somewhere. I may have not specified one
    when installing. Any ideas? Cheers, Paul...
  13. Mysql Tools Database - Opensource sql tools... (1)
    You can download mysql query web browser on http://www.mysql.com you also can download plugin
    there...like conector mysql from visual basic ,java,etc with my sql query tool browser you can make
    and maintance youre database sql easily because use gUI interface..!!...



Looking for mysql, query, problems,

Searching Video's for mysql, query, problems,
advertisement



Mysql Query Problems - I need some help or a tutorial?



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE