|
 |
|
เรื่องของการสมัครสมาชิกคับ รายละเอียดด้านในคับ ช่วยหน่อยนะคับ |
|
 |
|
|
 |
 |
|
ผมลองสมัครสมาชิก ลองป้อน username ซ้ำกัน มันไม่เช็คเงื่อนไขว่า ห้ามซ้ำคับ ดูให้ทีคับ
ถ้าเป็นไปได้ผมอยากให้ username กับ อีเมล ไม่ซ้ำกันคับ
Code (PHP)
<?
mysql_connect("localhost","root","root");
mysql_select_db("project");
mysql_query("set names UTF8");
if(trim($_POST["member_id"]) == "")
{
echo "<script>alert('กรุณากรอกไอดี');history.back();</script>";
exit();
}
if(trim($_POST["member_password"]) == "")
{
echo "<script>alert('กรุณากรอกรหัสผ่าน');history.back();</script>";
exit();
}
if($_POST["member_password"] != $_POST["confirm_password"])
{
echo "<script>alert('รหัสผ่านจะต้องเหมือนกัน กรุณากรอกรหัสผ่านใหม่');history.back();</script>";
exit();
}
if(trim($_POST["member_Firstname"]) == "")
{
echo "<script>alert('กรุณากรอกชื่อของคุณลงไป');history.back();</script>";
exit();
}
if(trim($_POST["member_Lastname"]) == "")
{
echo "<script>alert('กรุณากรอกนามสกุลของคุณลงไป');history.back();</script>";
exit();
}
if(trim($_POST["member_sex"]) == "")
{
echo "<script>alert('กรุณาระบุเพศของคุณด้วย');history.back();</script>";
exit();
}
if(trim($_POST["member_address"]) == "")
{
echo "<script>alert('กรุณากรอกข้อมูลที่อยู่ของคุณ');history.back();</script>";
exit();
}
if(trim($_POST["member_phone"]) == "")
{
echo "<script>alert('กรุณากรอกเบอร์โทรศัพท์ของคุณ');history.back();</script>";
exit();
}
if(trim($_POST["member_email"]) == "")
{
echo "<script>alert('กรุณากรอกอีเมล์ของคุณ');history.back();</script>";
exit();
}
$strSQL = "SELECT * FROM member WHERE member_id = '".trim($_POST['member_id'])."' ";
$objQuery = mysql_query($strSQL) or die(mysql_error());
if($objResult)
{
echo "member_id already exists!";
}
else
{
$strSQL = "INSERT INTO member (member_id,member_password,member_Firstname, member_Lastname,member_sex,member_address,member_phone ,member_email,confirm_password) VALUES ('".$_POST["member_id"]."',
'".$_POST["member_password"]."','".$_POST["member_Firstname"]."' ,'".$_POST["member_Lastname"]."','".$_POST["member_sex"]."', '".$_POST["member_address"]."','".$_POST["member_phone"]."' ,'".$_POST["member_email"]."','".$_POST["confirm_password"]."')";
$objQuery = mysql_query($strSQL) or die(mysql_error());
echo "สมัครสมาชิกสำเร็จแล้ว<br>";
echo "<br> Go to <a href='index.php'>กลับไปยังหน้าแรก</a>";
}
mysql_close();
?>
Tag : PHP

|
|
 |
 |
 |
 |
Date :
2012-09-15 12:20:37 |
By :
bankclup |
View :
898 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณ check if($objResult) ทั้งๆที่ $objResult ยังไม่มีค่าน่ะครับ มันเลยไม่เช็ค
ปรับเป็บแบบนี้ดู
Code (PHP)
$strSQL = mysql_query("SELECT count(*) as checkdup FROM member WHERE member_id = '".trim($_POST['member_id'])."'");
$objResult = mysql_fetch_array($strSQL);
if($objResult['checkdup']>0)
{
echo "member_id already exists!";
}
|
 |
 |
 |
 |
Date :
2012-09-15 13:49:31 |
By :
mangkunzo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|