如何防止重複記錄在php mysql中的輸入?在插入表之前驗證輸入。在php/mysql中防止重複行插入
我目前正在爲我的網站構建一個用戶註冊部分,但如果在數據庫中找到重複的用戶名或電子郵件地址,他們想向他們展示錯誤。
編輯
這是我不得不遠到插入行......怎麼會在這裏我實現這兩種回答:
<?php
if (array_key_exists('confirm',$_POST)) {
$Cuser = $_POST['Cuser'];
$Cemail = $_POST['Cemail'];
$Cpassword = $_POST['Cpassword'];
$md5password = md5($_POST['Cpassword']);
mysql_query("INSERT INTO tbl_users (`username`,`email`,`password`)
VALUES ('$Cuser', '$Cemail', '$md5password')");
echo "Thank you. The user <b>".$Cuser." (".$Cemail.")</b> has been successfully added to the database.<p>
<a href='myaccount.php' class='form'>Return</a>";
exit;
}
?>
我猜,我可以實現這一切在如果... else語句?
1爲適當的數據庫設計在「處理它的代碼「 – sholsinger 2010-12-02 16:02:21