|
 |
|
ถาม?? code ตรวจสอบการกรอกข้อมูลในแบบฟอร์มแบบตรวจสอบทุกช่อง |
|
 |
|
|
 |
 |
|
สมมุตินะครับสมมุติ
สมมุติว่า
มีบุคคลซักคนหนึ่งส่งข้อมูลผ่านแบบformแล้วไม่ได้กรอกอะไรเลย
แต่phpแสดงแค่ "คุณไม่ได้กรอกชื่อผู้ใช้.
ทั้งๆที่ผมต้องการให้แสดงทั้งหมดเลยว่าไม่ได้กรอกอะไรบ้าง ทำยังไงครับ
นี่โค้ดครับ
Code
<?
////////////////////////////////////
/////////*Page Config Zone*/////////
////////////////////////////////////
$pagename = "Register";
$pageperm = "guest";
$ref = $_SERVER['HTTP_REFERER'];
$regallow = ""; //Don't type anything when allow and type " disabled" when deny
?>
<?php require("../header.php"); ?>
<?
if (!isset($_POST['finreg'])) {
?>
<!--Pagecode-->
<p align="center"><img src="http://<? echo"$servername"; ?>/img/register.jpg" width="404" height="169"></p>
<h2 align="center"><strong>Register - สมัครสมาชิก</strong></h2>
<form action="<? $PHP_SELF; ?>" method="post" name="register">
<table width="90%" border="1" align="center" cellpadding="5" cellspacing="0" id="registermember">
<tr>
<td>Username [A-Z,a-z,0-9,_เท่านั้น]</td>
<td><input name="username" type="text" maxlength="20" placeholder="Username" required<? echo"$regallow"; ?>></td>
</tr>
<tr>
<td>Password [A-Z,a-z,0-9,_เท่านั้น]</td>
<td><input name="password" type="password" maxlength="64" placeholder="Password" required<? echo"$regallow"; ?>></td>
</tr>
<tr>
<td>Re-Password [A-Z,a-z,0-9,_เท่านั้น]</td>
<td><input name="repassword" type="password" maxlength="64" placeholder="Re-Password" required<? echo"$regallow"; ?>></td>
</tr>
<tr>
<td>ชื่อเล่น</td>
<td><input name="nickname" type="text" maxlength="20" placeholder="Nickname" required<? echo"$regallow"; ?>></td>
</tr>
<tr>
<td>Email [ใช้ในการยืนยันการสมัคร]</td>
<td><input name="email" type="text" maxlength="64" placeholder="Email" required<? echo"$regallow"; ?>></td>
</tr>
<tr>
<td>Re-Email [กรอกให้เหมือนข้างบน]</td>
<td><input name="reemail" type="text" maxlength="64" placeholder="Re-Email" required<? echo"$regallow"; ?>></td>
</tr>
<tr>
<td>เพศ [Sex]</td>
<td>
<select name="sex"<? echo"$regallow"; ?>>
<option value="0" selected="selected">โปรดเลือก</option>
<option value="1">ชาย</option>
<option value="2">หญิง</option>
<option value="3">ชายชอบชาย</option>
<option value="4">หญิงชอบหญิง</option>
</select></td>
</tr>
<tr>
<td>Facebook</td>
<td><input name="facebook" type="text" maxlength="64" placeholder="facebook"<? echo"$regallow"; ?>></td>
</tr>
<tr>
<td>เกี่ยวกับฉัน [เวลาคนอื่นเข้ามาดูหน้าโปรไฟล์ของเรา]</td>
<td><textarea name="aboutme" cols="45" rows="5" placeholder="เขียนเกี่ยวกับตัวเรา"<? echo"$regallow"; ?>></textarea></td>
</tr>
<tr>
<td colspan="2" style="text-align:center; vertical-align:central">
<input name="finreg" type="submit" class="btn btn-danger btn-large" value="จะเปิดให้สมัครในอนาคต"<? echo"$regallow"; ?>>
</td>
</tr>
</table>
</form>
<? }
else
{
?>
<?php
require("../function/db1_connect.php");
mysql_select_db($db1_name) or die("ขออภัยไม่สามารถติดต่อฐานข้อมูลได้");
$username=mysql_real_escape_string($_POST[username]);
$password=mysql_real_escape_string($_POST[password]);
$repassword=mysql_real_escape_string($_POST[repassword]);
$nickname=mysql_real_escape_string($_POST[nickname]);
$email=mysql_real_escape_string($_POST[email]);
$reemail=mysql_real_escape_string($_POST[reemail]);
$sex=mysql_real_escape_string($_POST[sex]);
$facebook=mysql_real_escape_string($_POST[facebook]);
$aboutme=mysql_real_escape_string($_POST[aboutme]);
if(trim($username) == "")
{
echo "กรุณาใส่ชื่อผู้ใช้";
}
if(trim($password) == "")
{
echo "กรุณาใส่รหัสผ่าน";
}
if($password != $repassword)
{
echo "รหัสผ่านทั้ง2ช่องไม่ตรงกัน";
}
if(trim($nickname) == "")
{
echo "กรุณาใส่ชื่อเล่น";
}
if(trim($email) == "")
{
echo "กรุณากรอกEmail";
}
if(trim($sex) == "0")
{
echo "กรุณาเลือกเพศ";
}
$strSQL = "SELECT * FROM $tb_member WHERE username = '".trim($username)."' ";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
if($objResult)
{
echo "มีชื่อผู้ใช้นี้ในระบบแล้ว";
}
if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email))
{
echo "Emailผิดรูปแบบ";
}
else
{
$sql = "INSERT INTO $tb_member (id,username,password,nickname,email,sex,facebook,aboutme,status) VALUES (NULL,'".$username."','".$password."','".$nickname."','".$email."','".$sex."','".$facebook."','".$aboutme."','unactivate')";
mysql_query($sql);
?>
<div class="alert alert-info">
<h2><strong>ลงทะเบียนเรียบร้อยแล้ว</strong></h2><br>
กรุณาเช็คEmailของท่านเพื่อยืนยันบัญชี<br>
<?
}
?>
<a href="<? echo"$ref"; ?>">กลับไปหน้าที่แล้ว</a>
</div>
<?
}
?>
<?php require("../footer.php"); ?>
Tag : PHP

|
|
 |
 |
 |
 |
Date :
2013-12-26 20:36:17 |
By :
KingdomOfGolf |
View :
1267 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
if(trim($username) == "")
{
echo "กรุณาใส่ชื่อผู้ใช้";
exit();
}
|
 |
 |
 |
 |
Date :
2013-12-27 09:18:55 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|