Mysql Query Problems - I need some help or a tutorial?
TheChosenDarkness
Mar 16 2008, 04:50 AM
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?
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.
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:
SQL
SELECT * FROMmembersWHEREid=''
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.
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","...
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. ...
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 ...
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...
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...
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?...
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 ...
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!...
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...
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...
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..!!...
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.