|
|
|
อยากจะให้แสดง alert ว่า username นี้ถูกใช้ไปแล้วครับ ขอคำแนะนำครับ |
|
|
|
|
|
|
|
Code (PHP)
<?PHP include_once 'include/condb.php'; ?>
<?PHP
try{
$dbh->beginTransaction();
//if แบบย่อ
//$x == 1 ? "OK" : "NO";
// input form
$user_id= $_POST['user_id'];
$loginname=!empty($_POST['loginname'])?$_POST['loginname']:null;
if(isset($_POST['password'])){$password=$_POST['password'];}
$name=!empty($_POST['name'])?$_POST['name']:null;
$pid=!empty($_POST['pid'])?$_POST['pid']:null;
$tel=!empty($_POST['tel'])?$_POST['tel']:null;
$email=!empty($_POST['email'])?$_POST['email']:null;
$priority_id=!empty($_POST['priority_id'])?$_POST['priority_id']:null;
if($user_id==0){ // Add
$sth=$dbh->prepare('insert into user (loginname,password,name,pid,tel,email,priority_id) values (?,md5(?),?,?,?,?,?)');
$result=$sth->execute(array($loginname,$password,$name,$pid,$tel,$email,$priority_id));
} else { // Edit
$sth=$dbh->prepare('update user set loginname=?,password=md5(?),name=?,pid=?,tel=?,email=?,priority_id=? where user_id=?');
$result=$sth->execute(array($loginname,$password,$name,$pid,$tel,$email,$priority_id,$user_id));
}
$dbh->commit(); // complete
if($result>0){
$json=array('status'=>'Yes');
}else{
$json=array('status'=>'No');
}
echo json_encode($json);
}catch(exception $e){
$dbh->rollback();
echo "Error :".$e->getMessage();
}
require_once 'include/globals_end.php' ;
Tag : PHP
|
|
|
|
|
|
Date :
2021-04-27 00:20:43 |
By :
punza2020 |
View :
596 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
$user = "select * from users where username='username'";
//count user
if(count($user)>0){
echo "username นี้ถูกใช้ไปแล้ว"; die;
}
|
ประวัติการแก้ไข 2021-04-28 12:17:46
|
|
|
|
Date :
2021-04-28 12:17:23 |
By :
mongkon.k |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|