|
 |
|
โค้ดสมัครสมาชิกคะ กรอกข้อมูลครบทุกช่องแล้ว แต่ทำไมยังแจ้งว่า "กรุณาระบุชื่อจริง" ช่วยดูโค้ดให้หน่อยนะคะ ขอบพระคุณมากนะคะ |
|
 |
|
|
 |
 |
|
<?php
//This function will display the registration form
function register_form(){
$date = date('D, M, Y');
echo "<form action='?act=register' method='post'>"
."<table width='200' cellspacing='1'>"
."<tr>"
."<td>ชื่อผู้ใช้:<input type='text' name='username' size='30'><br><td>"
."</tr>"
."<tr>"
."<td>รหัสผ่าน: <input type='password' name='password' size='30'><br><td>"
."</tr>"
."<tr>"
."<td>ยืนยันรหัสผ่าน: <input type='password' name='password_conf' size='30'><br></td>"
."</tr>"
."<tr>"
."<td>อีเมล: <input type='text' name='email' size='30'><br></td>"
."</tr>"
."<tr>"
."<td>ชื่อจริง: <input type='text' name='fname' size='30'><br></td>"
."</tr>"
."<tr>"
."<td>นามสกุล: <input type='text' name='lname' size='30'><br></td>"
."</tr>"
."<tr>"
."<td>บ้านเลขที่: <input type='text' name='homenum' size='30'><br></td>"
."</tr>"
."<tr>"
."<td>ตำบล: <input type='text' name='district' size='30'><br></td>"
."</tr>"
."<tr>"
."<td>อำเภอ: <input type='text' name='canton' size='30'><br></td>"
."</tr>"
."<tr>"
."<td>จังหวัด: <input type='text' name='province' size='30'><br></td>"
."</tr>"
."<tr>"
."<td>รหัสไปรษณีย์: <input type='text' name='postal' size='30'><br></td>"
."</tr>"
."<tr>"
."<td>เบอร์โทรศัพท์: <input type='text' name='tel' size='30'><br></td>"
."</tr>"
."<tr>"
."<td><input type='submit' value='Register'>"
."</tr>"
."</table>"
."</form>";
}
//This function will register users data
function register(){
//Connecting to database
$connect = mysql_connect("localhost", "root", "1234");
if(!$connect){
die(mysql_error());
}
//Selecting database
$select_db = mysql_select_db("sangkapan", $connect);
if(!$select_db){
die(mysql_error());
}
//Collecting info
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
$pass_conf = $_REQUEST['password_conf'];
$email = $_REQUEST['email'];
$fname = $_REQUEST['m_firstname'];
$lname = $_REQUEST['m_lastname'];
$homenum = $_REQUEST['home_num'];
$district = $_REQUEST['m_district'];
$canton = $_REQUEST['m_canton'];
$province = $_REQUEST['m_province'];
$postal = $_REQUEST['m_postal'];
$tel = $_REQUEST['phone'];
//Here we will check do we have all inputs filled
if(empty($username)){
die("กรุณาระบุชื่อผู้ใช้!<br>");
}
if(empty($password)){
die("กรุณายืนยันรหัสผ่าน!<br>");
}
if(empty($pass_conf)){
die("ยืนยันรหัสผ่านอีกครั้ง!<br>");
}
if(empty($email)){
die("กรุณาระบุรหัสผ่าน!");
}
if(empty($fname)){
die("กรุณาระบุชื่อจริง!");
}
if(empty($lname)){
die("กรุณาระบุนามสกุล!");
}
if(empty($homenum)){
die("กรุณาระบุบ้านเลขที่!");
}
if(empty($district)){
die("กรุณาระบุตำบล!");
}
if(empty($canton)){
die("กรุณาระบุอำเภอ!");
}
if(empty($province)){
die("กรุณาระบุจังหวัด!");
}
if(empty($postal)){
die("กรุณาระบุรหัสไปรษณีย์!");
}
if(empty($tel)){
die("กรุณาระบุเบอร์โทร!");
}
//Let's check if this username is already in use
$user_check = mysql_query("SELECT username FROM member WHERE username='$username'");
$do_user_check = mysql_num_rows($user_check);
//Now if email is already in use
$email_check = mysql_query("SELECT email FROM member WHERE email='$email'");
$do_email_check = mysql_num_rows($email_check);
//Now display errors
if($do_user_check > 0){
die("Username is already in use!<br>");
}
if($do_email_check > 0){
die("Email is already in use!");
}
//Now let's check does passwords match
if($password != $pass_conf){
die("Passwords don't match!");
}
//If everything is okay let's register this user
$insert = mysql_query("INSERT INTO member (username, password, email,m_firstname,m_lastname,home_num,m_district,m_canton,m_province,m_postal,phone)
VALUES ('$username', '$password', '$email','$fname','$lname','$homenum','$district','$canton','$province','$postal','$tel')");
if(!$insert){
die("There's little problem: ".mysql_error());
}
echo $username.", you are now registered. Thank you!<br><a href=login.php>Login</a> | <a href=index.php>Index</a>";
}
switch($act){
default;
register_form();
break;
case "register";
register();
break;
}
?>
Tag : PHP, HTML/CSS

|
|
 |
 |
 |
 |
Date :
2014-06-30 17:06:26 |
By :
geegee |
View :
1607 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไล่ดูดีๆก็นิดเดียวเองนะครับ ในฟอร์ม html ประกาศ name = fname 
Code (PHP)
ชื่อจริง: <input type='text' name='fname' size='30'>
แต่พอตอนรับค่า ทำไมไม่รับ fname ละครับ
Code (PHP)
$fname = $_REQUEST['m_firstname'];
ที่ถูกต้อง ก็คือ 
Code (PHP)
$fname = $_REQUEST['fname'];
|
 |
 |
 |
 |
Date :
2014-06-30 17:12:10 |
By :
Manussawin |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คะ ขอบคุณมากๆ จะลองแก้ดูคะ
|
 |
 |
 |
 |
Date :
2014-06-30 18:28:24 |
By :
geegee |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|