User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 373,936 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,859 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser:
Views: 3709 | Replies: 5
Reply
Join Date: Apr 2004
Location: Tracy
Posts: 743
Reputation: Killer_Typo will become famous soon enough Killer_Typo will become famous soon enough 
Rep Power: 7
Solved Threads: 31
Killer_Typo's Avatar
Killer_Typo Killer_Typo is offline Offline
Master Poster

mySQL database searching for registration

  #1  
Jun 16th, 2004
i need to know the format to search for a user name in the database, im using PHP to submit the data

so far this is what ive got
[php]
@mysql_select_db("$DBName") or die("Unable to select
database $DBName");

$sqlquery = "INSERT INTO $table
VALUES('$id','$name','$email','$opinion')";

$results = mysql_query($sqlquery);

mysql_close();
[/php]

im using that to insert the data into the database, but i need to know the format to search the database to make sure that the username isnt already in use.

$sqlquery = "SEARCH * FROM table WHERE name =(username user wants)";

but i dont know how to tell it to output if the user name has infact been found or if it has not and the user name is good. any help would be greatly appreciated.
!!!!! WARNING YOUR COMPUTER MAY BE INFECTED WITH SPYWARE!!!! PAY AN OVER PRICED AMMOUNT TO HAVE SOMTHING FIXED WE PLACED THERE IN THE FIRST PLACE!!!!!!!!!

sound familiar, know how to block yourself and keep yourself clean.
_____________________
http://www.lavasoftusa.com/ -->adaware
http://www.safer-networking.org/en/index.html -->spybot S&D
http://www.javacoolsoftware.com/spywareblaster.html -->spywareblaster
http://www.javacoolsoftware.com/spywareguard.html -->spywareguard
_____________________
and dont forget to spread the reputation to those that deserve!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2002
Location: Long Island, NY
Posts: 1,134
Reputation: samaru is just really nice samaru is just really nice samaru is just really nice samaru is just really nice 
Rep Power: 12
Solved Threads: 2
Colleague
samaru's Avatar
samaru samaru is offline Offline
a.k.a inscissor

Re: mySQL database searching for registration

  #2  
Jun 16th, 2004
Try:

select count(user_name) as usercount from $table where user_name = '$name'

Then extract the value 'usercount' from the recordset and if it's 0, none exists. If it's greater than 0, then it exists.
_.:: my websites ::._
blog @ www.samaru.net * engi No Jutsu @ www.narutorp.net * portfolio @ shinylight.com
deviantART: inscissor
Reply With Quote  
Join Date: Apr 2004
Location: Tracy
Posts: 743
Reputation: Killer_Typo will become famous soon enough Killer_Typo will become famous soon enough 
Rep Power: 7
Solved Threads: 31
Killer_Typo's Avatar
Killer_Typo Killer_Typo is offline Offline
Master Poster

Re: mySQL database searching for registration

  #3  
Jun 16th, 2004
[php]
mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database"); //connecting to the database using the variable set
@mysql_select_db("$DBName") or die("Unable to select database $DBName"); //at connection to the databse select DBNAME (phpforms) or tell that it couldnt connect
//$sqlquery = "SELECT usr_name FROM $Table WHERE usr_name = '$_POST[usr_name]'";
$sqlquery = "SELECT COUNT(usr_name) FROM $Table WHERE usr_name = '$usr_name'";
$results = mysql_query($sqlquery);
echo "current user name " . $_POST[usr_name] . "<br />";
echo "query returned " . $sqlquery . "<br />";
echo "query returned " . $results . "<br />";
[/php]

i added the lines query returned .$sqlquery and query returned $results to see exactly what it was spewing out.

and heres the output of it now

current user name michael
query returned SELECT COUNT(usr_name) FROM reg_info WHERE usr_name = 'michael'
query returned Resource id #3
sorry that user name has been taken! please use your browsers back button and try a different one!

what in the world is Resouce id #3??

also i believe using mysql_query is the wrong command, so i tried mysql_field_count() in its place, but it gave me an error saying that i used the wrong syntax within the () fields. I am determined to figure this out!...but it seems to be more advanced than i thought it to be when i first set out on this task to create a login. cuz after i figure this out, im creating a login/logout and a cookie which will automaticly log a user back in!! man this is gonna be fun!
!!!!! WARNING YOUR COMPUTER MAY BE INFECTED WITH SPYWARE!!!! PAY AN OVER PRICED AMMOUNT TO HAVE SOMTHING FIXED WE PLACED THERE IN THE FIRST PLACE!!!!!!!!!

sound familiar, know how to block yourself and keep yourself clean.
_____________________
http://www.lavasoftusa.com/ -->adaware
http://www.safer-networking.org/en/index.html -->spybot S&D
http://www.javacoolsoftware.com/spywareblaster.html -->spywareblaster
http://www.javacoolsoftware.com/spywareguard.html -->spywareguard
_____________________
and dont forget to spread the reputation to those that deserve!
Reply With Quote  
Join Date: Feb 2002
Location: Long Island, NY
Posts: 1,134
Reputation: samaru is just really nice samaru is just really nice samaru is just really nice samaru is just really nice 
Rep Power: 12
Solved Threads: 2
Colleague
samaru's Avatar
samaru samaru is offline Offline
a.k.a inscissor

Re: mySQL database searching for registration

  #4  
Jun 16th, 2004
You're executing the sql statement but you're not retrieving anything. You have to fetch the results into something like an associative array, so you use mysql_fetch_assoc(). Try this:

[php]
$Table = 'user';
$name = 'rootx';
mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database"); //connecting to the database using the variable set
@mysql_select_db("$DBName") or die("Unable to select database $DBName"); //at connection to the databse select DBNAME (phpforms) or tell that it couldnt connect
$sqlquery = "SELECT COUNT(user_name) as user_name FROM $Table WHERE user_name = '$name'";
$results = mysql_query($sqlquery);
$user_count = mysql_fetch_assoc($results);
echo "current user name " . $_POST['usr_name'] . "<br />";
echo "query returned " . $sqlquery . "<br />";
echo "query returned " . $user_count['user_name'] . "<br />";
[/php]

Also, don't retrieve form variables as $_POST[whatever], use the apostrophes like I did in the code.
_.:: my websites ::._
blog @ www.samaru.net * engi No Jutsu @ www.narutorp.net * portfolio @ shinylight.com
deviantART: inscissor
Reply With Quote  
Join Date: Apr 2004
Location: Tracy
Posts: 743
Reputation: Killer_Typo will become famous soon enough Killer_Typo will become famous soon enough 
Rep Power: 7
Solved Threads: 31
Killer_Typo's Avatar
Killer_Typo Killer_Typo is offline Offline
Master Poster

Re: mySQL database searching for registration

  #5  
Jun 16th, 2004
heres the error i get

You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM reg_info WHERE usr_name = 'michael'' at line 1

and heres the code that gives it.



[php]mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database"); //connecting to the database using the variable set
@mysql_select_db("$DBName") or die("Unable to select database $DBName"); //at connection to the databse select DBNAME (phpforms) or tell that it couldnt connect
$sqlquery = "SELECT COUNT(usr_name) as FROM $Table WHERE usr_name = '$usr_name'";
if (!$sqlquery)
{
echo(mysql_error());
}
else
{
$results = mysql_query($sqlquery);
if (!$results)
{
echo(mysql_error());
}
else
{
$user_count = mysql_fetch_assoc($results);
if (!$user_count)
{
echo(mysql_error());
}
else
{
echo "current user name " . $_POST['usr_name'] . "<br />";
echo "query returned " . $sqlquery . "<br />";
echo "query returned " . $results . "<br />";
echo "array returned " . $user_count . "<br />";
}
}
}
[/php]

i think my main problem is that im new to php and mysql, and i dont quite no all of the syntax.


sort ($user_count)
foreach ($user_count as $array)

if ($array >= 1)

stop

else

continue.
Last edited by samaru : Jun 16th, 2004 at 9:42 pm.
!!!!! WARNING YOUR COMPUTER MAY BE INFECTED WITH SPYWARE!!!! PAY AN OVER PRICED AMMOUNT TO HAVE SOMTHING FIXED WE PLACED THERE IN THE FIRST PLACE!!!!!!!!!

sound familiar, know how to block yourself and keep yourself clean.
_____________________
http://www.lavasoftusa.com/ -->adaware
http://www.safer-networking.org/en/index.html -->spybot S&D
http://www.javacoolsoftware.com/spywareblaster.html -->spywareblaster
http://www.javacoolsoftware.com/spywareguard.html -->spywareguard
_____________________
and dont forget to spread the reputation to those that deserve!
Reply With Quote  
Join Date: Feb 2002
Location: Long Island, NY
Posts: 1,134
Reputation: samaru is just really nice samaru is just really nice samaru is just really nice samaru is just really nice 
Rep Power: 12
Solved Threads: 2
Colleague
samaru's Avatar
samaru samaru is offline Offline
a.k.a inscissor

Help Re: mySQL database searching for registration

  #6  
Jun 16th, 2004
There's an error in your SQL statement:

$sqlquery = "SELECT COUNT(usr_name) as FROM $Table WHERE usr_name ='$usr_name'";

The "as" statement assigns aliases to columns. In this case, your're not assigning an alias to the result that count(user_name) spits out. You need to put a name for a column's alias after the "as" but you skipped that and just wrote the "FROM."

Killer_Typo, check your PMs.
Last edited by samaru : Jun 17th, 2004 at 8:14 pm.
_.:: my websites ::._
blog @ www.samaru.net * engi No Jutsu @ www.narutorp.net * portfolio @ shinylight.com
deviantART: inscissor
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb MySQL Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the MySQL Forum

All times are GMT -4. The time now is 6:29 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC