|
|
|
รบกวนช่วยดูโค๊ด Register form ทีคะ ติดปัญหาตรงที่่ตรวจ id และ username ซ้ำคะ |
|
|
|
|
|
|
|
สวัสดีคะ
ตอนนี้กำลังทำฟอร์ม register อยู่ โดยจะต้องเช็คว่า รหัสพนักงานซ้ำหรือไม่ (PK) และ username ที่ใช้ซ้ำหรือไม่ คือสามารถตรวจสอบได้คะ แต่ติดปัญหาตรงที่ ถ้า รหัสพนักงานซ้ำก็จะขึ้นมาให้ แต่ดันไปขึ้นคำอื่นๆที่อยู่ใน else อื่นด้วยคะ อยากจะหาวิธีหยุดCode (PHP)
<?
include_once("connect.php");
$strsql="select * from employee where emp_id ='".trim($_POST['emp_id'])."'";
$strobj=mysql_query($strsql);
$rs=mysql_fetch_assoc($strobj);
if($rs)
{
echo "Emp_ID Existed";
echo "<br> Go to <a href='frm_register.php'>Register page</a>";
}
$strsql="select * from employee where username ='".trim($_POST['username'])."'";
$strobj=mysql_query($strsql);
$rs=mysql_fetch_assoc($strobj);
if($rs)
{
echo "Username Existed";
echo "<br> Go to <a href='frm_register.php'>Register page</a>";
}
else{
$strsql="insert into employee (emp_id,username,password,emp_name,emp_lname,emp_position,emp_email,emp_status) values ('".$_POST['emp_id']."','".$_POST['username']."','".$_POST['password']."','".$_POST['emp_name']."','".$_POST['emp_lname']."','".$_POST['emp_position']."','".$_POST['emp_email']."','".$_POST['emp_status']."')";
$rs=mysql_query($strsql);
echo "Register Completed<br>";
echo "<br> Go to <a href='frm_login.php'>Login page</a>";
}
mysql_close();
?>
****พอรันแล้ว มันจะเป็นแบบนี้คะ****
Emp_ID Existed
Go to Register pageRegister Completed
Go to Login page
*****อยากจะเอาตรงคำว่า*****
Register Completed
Go to Login page
ออกคะ ไม่รุ้จะปิด if else อะไรยังไง พยายามทำแล้วแต่ยังไม่ได้สักทีคะ
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2012-09-13 21:33:13 |
By :
delightlita |
View :
979 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองใช้ exit(); ดูครับ
|
|
|
|
|
Date :
2012-09-13 21:34:02 |
By :
billkyz5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ตามนั้นครับ ใช้ exit(); ครับ
|
|
|
|
|
Date :
2012-09-14 06:12:11 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณมากๆเลยคะ
ทำได้แล้วคะ
ตอนแรกดันไปลอง break countinue แล้วลืมว่ามีอีกตัวนึงแต่นึกไม่ออกจริงๆ - -"
|
|
|
|
|
Date :
2012-09-14 08:43:02 |
By :
delightlita |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|