|
|
Php + Mysql Question! - While inserting data into MySQL, how can I know if the data I'm in | ||
Discussion by GaiaZone with 5 Replies.
Last Update: January 12, 2008, 7:55 pm | |||
![]() |
|
|
I have this, but it doesn't appear to work...
CODE
$result = mysql_query("SELECT * FROM users WHERE username='$username'");if($result == 1)
{
echo '<h1>ERROR!</h1>The username you have chosen already exists!';
}
You can use
CODE
$count = mysql_num_rows($result);
Then compare $count == 1 in your if statement.
Thank you. =]
CODE
$result = mysql_query("SELECT count(*) as count FROM users WHERE username='$username'");
$count = mysql_result($result, 0, "count");
and I would change the compare to $count > 0 in the if statement, just to be sure.
QUOTE (slu)
...or let MySQL do the counting:CODE
$result = mysql_query("SELECT count(*) as count FROM users WHERE username='$username'");
$count = mysql_result($result, 0, "count");
and I would change the compare to $count > 0 in the if statement, just to be sure.
Link: view Post: 367935
That would result in an error if there were no rows matching that query. mysql_num_rows is the best function to use.
Similar Topics:
Mysql Php Apache Downloads And Se...
Php And Mysql Programming
Best Php And Mysql Editor For Noobs
Analog Clock (4)
|
(4) Counting Variables?
|
Loading...
HOME 





PHP and MYSQL - Editing and Deleting Data
An introduction to MySQL
Flash guest book frontend part 1 -flash, PHP, MySQL

