Jump to content

Recommended Posts

You can do a SELECT query but use the WHERE clause ie:
[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] users_row_name [color=green]FROM[/color] [color=orange]user_table[/color] [color=green]WHERE[/color] users_row_name [color=orange]=[/color] [color=red]"someNameHere"[/color] [!--sql2--][/div][!--sql3--]
Then in PHP you use the mysql_num_rows function and check whether the query returned more than one name. Heres some code:
[code]<?php

$query = "SELECT users_row_name FROM user_table WHERE users_rwo_name = "someNameHere";
$result = mysql_query($query);

if(mysql_num_rows($result)  !=  '1')
{
    echo "unfortunatly that name has alread been taken, please try another";
}
else
{
    echo "Hay! You're in luck that name is available";
}

?>[/code]
Also I would recommend you to change the row that stores your website users to be Unique.
[!--quoteo(post=365329:date=Apr 16 2006, 04:41 PM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Apr 16 2006, 04:41 PM) [snapback]365329[/snapback][/div][div class=\'quotemain\'][!--quotec--]
You can do a SELECT query but use the WHERE clause ie:
[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] users_row_name [color=green]FROM[/color] [color=orange]user_table[/color] [color=green]WHERE[/color] users_row_name [color=orange]=[/color] [color=red]"someNameHere"[/color] [!--sql2--][/div][!--sql3--]
Then in PHP you use the mysql_num_rows function and check whether the query returned more than one name. Heres some code:
[code]<?php

$query = "SELECT users_row_name FROM user_table WHERE users_rwo_name = "someNameHere";
$result = mysql_query($query);

if(mysql_num_rows($result)  !=  '1')
{
    echo "unfortunatly that name has alread been taken, please try another";
}
else
{
    echo "Hay! You're in luck that name is available";
}

?>[/code]
Also I would recommend you to change the row that stores your website users to be Unique.
[/quote]


Thank you is there a shorter way cheers.
Yes there, and that is to change your users_row_name row to a unique identifier. You can do this in PHPMyAdmin by editing the users table and clicking the Unique Identidier option on theu sers_row_name row.

This way MySQL will check when it inserts a new record that the username being inserted doesn't already exist users_row_name row in the database. If there is then if you have the [i]or die(mysql_error())[/i] clause after you do mysql_query function MySQL will report back with an error.
[!--quoteo(post=365335:date=Apr 16 2006, 05:07 PM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Apr 16 2006, 05:07 PM) [snapback]365335[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Yes there, and that is to change your users_row_name row to a unique identifier. You can do this in PHPMyAdmin by editing the users table and clicking the Unique Identidier option on theu sers_row_name row.

This way MySQL will check when it inserts a new record that the username being inserted doesn't already exist users_row_name row in the database. If there is then if you have the [i]or die(mysql_error())[/i] clause after you do mysql_query function MySQL will report back with an error.
[/quote]

Thank you can you also kindly show how to count the number of times the user name is in the database thank you.
You use my previous SQL Query with mysql_num_rows. You dont need to count how many times of the same username is in the database, becuase of the unique identifier option will only 1 occurance of the same username in the database.
I have done the above i wanted to no
how to count the users name in the database thank you cheers.

my example to count number of users names cheers.
[code]
$db=mysql_connect("xxxx","xxxxx","xxxx");
mysql_select_db("schollwork",$db);
$query="SELECT name from work";
$result=mysql_query($query);
for($i=0; $i<=count($result); $i++){
echo "<br>'".$name[$i]."'<br>";
exit;
}
[/code]
So you want to see how many users are in your database? Then you can do this:
[code]$db = mysql_connect("xxxx","xxxxx","xxxx");

mysql_select_db("schollwork",$db);

$query = "SELECT COUNT(name) as users FROM work";
$result = mysql_query($query);
$user = mysql_fetch_array($result);

echo "There are <b>" . $user['users'] . "</b> users currently in the database!";[/code]
[!--quoteo(post=365360:date=Apr 16 2006, 07:02 PM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Apr 16 2006, 07:02 PM) [snapback]365360[/snapback][/div][div class=\'quotemain\'][!--quotec--]
So you want to see how many users are in your database? Then you can do this:
[code]$db = mysql_connect("xxxx","xxxxx","xxxx");

mysql_select_db("schollwork",$db);

$query = "SELECT COUNT(name) as users FROM work";
$result = mysql_query($query);
$user = mysql_fetch_array($result);

echo "There are <b>" . $user['users'] . "</b> users currently in the database!";[/code]
[/quote]

how do i count the number of users via name cheers grate!

for example name is john

How can i combine these two statements together, i wont to show the user that there is a user in the database via a number and not let that entry go into the database.
[code]
$db=mysql_connect("localhost","xxxx","xxxx");
mysql_select_db("schollwork",$db);

$query = "SELECT COUNT(name) as users FROM work where name='$name'";
$result = mysql_query($query);
$user = mysql_fetch_array($result);

echo "<br>There are <b>" . $user['users'] . "</b> same username's in the database";

mysql_select_db("schollwork",$db);
$query = "SELECT name FROM work where name='$name'";
$result = mysql_query($query);
if(mysql_num_rows($result)!==1){
echo" sorry $name name tacken";
echo"<br><my url back to the form>Please try agin</a>";
exit;
}
[/code]
cheers!
I just editted your code a little, you don't need the second SQL statement.

[code]
$query = "SELECT COUNT(name) as users FROM work where name='$name'";
$result = mysql_query($query);
$user = mysql_fetch_array($result);

echo "<br>There are <b>" . $user['users'] . "</b> same username's in the database";
if($user['users'] >= 1){
    echo" sorry $name name taken";
    echo"<br><my url back to the form>Please try agin</a>";
    exit;
}
[/code]

This is it complete but wont to shorten it down please help cheers.

If a user enters a user name tacken they get a message, Also if the user enter a email address tacken the user gets a message, If the user gets smart and enter a diffrent username with an existing email address the user gets a message And finally if the user enter reall email but with an existing username the user gets a message.


solved but nedds to be shortend like above cheers.


[code]

$db=mysql_connect("localhost","xxxx","xxxx");
mysql_select_db("schollwork",$db);
$query = "SELECT email FROM work where email='$email'";
$result = mysql_query($query);
if(mysql_num_rows($result)> 1){
echo"<b> sorry $email email tacken";
echo"<br><a href='my url'>Please try agin</a>";
exit;
}


$db=mysql_connect("localhost","xxxx","xxxx");
mysql_select_db("schollwork",$db);

$query = "SELECT COUNT(name) as users FROM work where name='$name'";
$result = mysql_query($query);
$user = mysql_fetch_array($result);

echo "<b>There are <b>" . $user['users'] . "</b> ";


$db=mysql_connect("localhost","xxxx","xxxx");
mysql_select_db("schollwork",$db);
$query = "SELECT name FROM work where name='$name'";
$result = mysql_query($query);
if(mysql_num_rows($result)==1){
echo" sorry $name name tacken";
echo"<br><a href='my url";
die;
}
[/code]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.