FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Select more than 1 field in a database





alalex
How can I query a database to get two fields in the same row??
I wanted to find a username and a password in a database, that would be in the same row, and I used this:
Code:

$query = "SELECT * FROM users WHERE username = '$username' and password = '$password';"
$result = mysql_query($query);


I want to create a login thing...
thnn
May i suggest you do this:
Code:

$query = "SELECT * FROM users WHERE username = '$username' and password = '$password';"
$result = mysql_query($query);
$numofaccounts = mysql_num_rows($result);
if ($numofaccounts == 1)
{
 //log the user in
 echo "You are logged in";
}
else
{
 echo "Something is wrong";
}

Of course this is very basic and you could make it more powerful. This system works on the basis that only one user has that username and password.

I hope you have your registration form so only one user can have a username.
alalex
Actually, I am working on that. I am new in MySQL, and I was thinking in something like this:

In the registration page, search for users with that username, and if there is one, return to the registratioon form, but until now, I didn't know how to search for data other than the id...

Thanks a lot!
avk
I think u should use

Quote:

$query="SELECT * FROM users where username='$username'";
$result=mysql_query($query);
while($row=mysql_fetch_array($result,MYSQL_ASSOC)){
$username1={$row['username']};
// The table and the content out here...
}


That's it
openaasman
to get only two fields from the table from a row.

write

select field1, field2 from tablename where -----;

you need to specify 2 field names you want to retrieve
alalex
OK, thanks, I will try that! Very Happy
Related topics
Database connection class!
Chatroom
phpBB - Installation Tutorial
myBBoard - Installation Tutorial
Joomla! - Installation Tutorial
AJAX tutorial [2nd part now updated]
PhpNuke Installation Tutorial
Using SQL to retrieve database information
[HTML][FORM]change the size of a input select
SQL.....Where to start?
Joomla Support
What to learn first?
Help me with MySQL Account Maintenance and phpBB 2.0.15 :((
SLOW UPLOADING AN SQL FILE
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.