View Full Version : Connection to table
How do you use PHP to retrieve user data stored in a table? i.e.:
THE TABLE: 'SomethingRather.exe'
------------------------------------
NAME | PASSWORD | ACCESS LEVEL |
------------------------------------
NAME2|PASSWORD2|ACCESS LEVEL2|
------------------------------------
NAME3|PASSWORD3|ACCESS LEVEL3|
------------------------------------
Say I want to find NAME2's password and access level. What do I do? And here is the catch: I need to search through the users to find the one I want. i.e. they type Name2 and I need to find their password, etc.
Anyone?
Thanks
thetestingsite
04-07-2007, 12:30 AM
Have you tried to use this query?
SELECT * FROM `table` WHERE `NAME`='NAME2'
Of course, you will have to substitue the above to work with your code.
Hope this helps.
Have you tried to use this query?
SELECT * FROM `table` WHERE `NAME`='NAME2'
Of course, you will have to substitue the above to work with your code.
Hope this helps.
I don't know what that is. Can you explain it better?
>>>>>>>>>SORRY THIS POSTED TWICE. My IE messed up. . .
thetestingsite
04-07-2007, 02:11 AM
In your PHP code, try using the query that I posted above.
Example:
<?php
$name = $_REQUEST['name'];
include('dbconnect.php'); //this will open the connection to the database
$info = mysql_query("SELECT * FROM `tableNameHere` WHERE `NAME`='$name'");
while ($qry = mysql_fetch_array($info)) {
echo $qry['password'];
}
?>
Basically what the above does is search through the database and returns results of the rows in the table that the column "NAME" matches to the variable "$name". After it gets the results, we assign the variable $qry to fetch the array of each row, and print the password for each name (that gets returned) onto the screen.
Hope this helps.
I think I get it, but is there some kind of tutorial on the subject that I can study? I've been looking on google, but I'm not entirely sure what to look for. . .
mburt
04-07-2007, 05:09 PM
That's a PHP example of working with a MySql database. I'm hoping you know what PHP is, and how to use it, because here's a great PHP/MySql tut.
http://php-mysql-tutorial.com/
It'll show you the basic MySql command lines and how to use them with PHP.
thetestingsite
04-07-2007, 05:09 PM
Here's a few websites:
http://www.php-mysql-tutorial.com/
http://www.tizag.com/mysqlTutorial/
http://dev.mysql.com/doc/refman/5.0/en/select.html
Hope this helps.
EDIT: Sorry Mike, cross-posted.
mburt
04-07-2007, 05:18 PM
EDIT: Sorry Mike, cross-posted.
Happens to me all the time :), no prob.
Also:
http://www.freewebmasterhelp.com/tutorials/phpmysql
I found that one useful.
Thank you, mburt and thetestingsite! I'll check out those sites and see what I can dig up.
ARGH! I REALLY don't want to have to do all of that. . . Is there no way to not use MySQL and just use the table directly?
mburt
04-07-2007, 06:28 PM
Use the MySql command client. Or phpMyAdmin.
Use the MySql command client. Or phpMyAdmin.
But is there nothing else? Can I not just have it read through a table or something? MySql will be a pain for me to manage if I have as many users as I am hoping to have on my new site.
mburt
04-07-2007, 06:37 PM
MySql makes everything very easy.
Query for creating the table:
CREATE TABLE users (id int(6) auto_increment NOT NULL,username varchar(15) NOT NULL,password varchar(15) NOT NULL,other fields,PRIMARY KEY(id),UNIQUE id(id),KEY id_2(id))
Then insertion would be as easy as:
INSERT INTO users VALUES('','username','password','other values')
. . . In this case, I'd rather not have to use that. Is that a "no" to my question?
A second idea: is there a way to impot a table into MySQL?
mburt
04-07-2007, 07:26 PM
A second idea: is there a way to impot a table into MySQL?
Yes. But it is complex. Try searching the forums, I remember there being something about this before.
That's excellent news! I'll check and see if this solves things for me. It's still not ideal, but oh well. . .
boxxertrumps
04-07-2007, 08:14 PM
When i switched from windows to linux, i just copied the mysql data directory into the new directory on linux...
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.