我在登記表,以防止對多個用戶名下面的代碼創建:我將如何停止多個電子郵件或用戶名?
connect_db();
$check = mysql_query("SELECT username FROM school_users WHERE username = '$username'") or die(mysql_error());
$check2 = mysql_num_rows($check);
if ($check2 != 0) {
respond("error", "Sorry, the username ".$_POST['username']." is already in use. Please choose a different username.");}
不過,我也想檢查郵件,在同一個語句:
connect_db();
$check = mysql_query("SELECT username, email FROM school_users WHERE username = '$username' or email = '$email'") or die(mysql_error());
$check2 = mysql_num_rows($check);
if ($check2 != 0) {
if (???username???){
respond("error", "Sorry, the username ".$_POST['username']." is already in use. Please choose a different username.");}}
else if (???email???) {
respond("error", "Sorry, the username ".$_POST['username']." is already in use. Please choose a different username.");}}
從查詢中獲取用戶名和電子郵件,並檢查您的帖子值? – hank 2013-02-10 17:49:10
[**請不要在新代碼**中使用'mysql_ *'函數](http://bit.ly/phpmsql)。他們不再被維護[並且被正式棄用](http://j.mp/XqV7Lp)。看到[**紅框**](http://j.mp/Te9zIL)?學習[*準備的語句*](http://j.mp/T9hLWi),並使用[PDO](http://php.net/pdo)或[MySQLi](http://php.net/ mysqli) - [這篇文章](http://j.mp/QEx8IB)將幫助你決定哪個。 – Kermit 2013-02-10 18:01:34
^^^^儘可能真實,它對於常規的S.O用戶每天看到它10次以上有點繁瑣。 – 2013-02-10 18:21:39