PHP를 사용하여 양식의 데이터를 입력하려고합니다. 내가 뭔가이 잘못 갔다 mysql 중복 오류 처리
같은 잘못된 메시지가 나올 중복 된 데이터를 입력 할 때 :INSERT INTO customer VALUES('jamie9422','Jamie Lannister','sept of baelor','[email protected]',9422222222,0) Duplicate entry 'jamie9422' for key 'PRIMARY' "
대신, 나는 깨끗하고 오류 메시지를 표시합니다. 어떻게해야합니까? 지금까지 작성한 코드는 다음과 같습니다.
<?php
include_once "dbConnect.php";
$connection=connectDB();
if(!$connection)
{
die("Couldn't connect to the database");
}
$tempEmail = strpos("{$_POST["email"]}","@");
$customer_id=substr("{$_POST["email"]}",0,$tempEmail).substr("{$_POST["phone"]}",0,4);
//$result=mysqli_query($connection,"select customer_id from customer where customer_id='$customer_id' ");
//echo "customer_id is".$result;
$query = "SELECT * FROM CUSTOMER WHERE CUSTOMER_ID='$customer_id'";
$customer_idcip = $customer_id-1;
echo $customer_idcip;
if (mysql_query($query)) {
echo "It seems that user is already registered";
} else {
$command = "INSERT INTO customer VALUES('{$customer_id}','{$_POST["name"]}','{$_POST["address"]}','{$_POST["email"]}',{$_POST["phone"]},0)";
$res =$connection->query($command);
if(!$res){
die("<br>Something went wrong with this:{$command}\n{$connection->error}");
}
echo "Welcome ".$_POST["name"]." \nCongratulations on successful Registration. Refill your Wallet here";
//$cutomerRetrival = mysql_query("select from customer where customer_id='$customer_id'");
echo "<br>Please note your customer ID :".$customer_id;
}
/*if($result)
{
echo "Query Fired";
$dupentry = mysqli_num_rows($result);
if($dupentry==1)
{
echo "You are already Registered";
exit;
}
}*/
?>
데이터베이스 테이블에 이미 'jamie9422'라는 사용자가있다. – vaso123
삽입하기 전에 중복 키를 확인하십시오. – degr