-1
如何插入數據到數據庫而不重複的名稱例如,如果名稱在數據庫中顯示消息顯示消息怎麼做到這一點?插入到數據庫中不重複在PHP中
<?php
$username ="root";
$password ="";
$hostname="localhost";
$db="a";
$dbhandle=mysql_connect($hostname ,$username ,$password,$db)or die('not connect to the database because:'.mysql_error());
mysql_select_db($db,$dbhandle);
$myusername=$_POST['user'];
$mypassword=$_POST['pass'];
$mypassword_conf=$_POST['Password_conff'];
if($mypassword==$mypassword_conf)
{
$sql="INSERT INTO aa(username, password,pass_con) VALUES
('$myusername','$mypassword','$mypassword_conf')";
if(! mysql_query($sql,$dbhandle))
echo "not insert";
else
echo "insert is Done";
mysql_close();
}
else
{
echo "not insert to db found error";
}
?>
將名稱列作爲唯一鍵嗎? –