|
|
|
การตรวจสอบข้อมูลซ้ำ ใน Database ลองทำตามตัวอย่างแล้วไม่ได้ ไม่ทราบว่าติดตรงไหน ไม่มีข้อมูลแสดงไรเลย |
|
|
|
|
|
|
|
การตรวจสอบข้อมูลซ้ำ ใน Database ลองทำตามตัวอย่างแล้วไม่ได้ ไม่ทราบว่าติดตรงไหน ไม่มีข้อมูลแสดงไรเลย ผมทำตาม
http://www.itoffside.com/php-workshop-available-email-or-username-ajax/
ต้องทำยังไงครับ
index.php
Code (PHP)
<?php
session_start(); // we keep a session to save the captcha key
$status = "firstload";
if (isset($_POST['submit'])) {
isset($_POST['firstname']) ? $firstname = $_POST['firstname'] : $firstname = "";
isset($_POST['lastname']) ? $lastname = $_POST['lastname'] : $lastname = "";
isset($_POST['email']) ? $email = $_POST['email'] : $email = "";
isset($_POST['mobilephone']) ? $mobilephone = $_POST['mobilephone'] : $mobilephone = "";
$captchaKey = substr($_SESSION['key'],0,5);
$formKey = $_POST['formKey'];
if ( $formKey == $captchaKey ) {
if ( ($firstname) && ($lastname) ) {
include('library/opendb.php');
include('include/common/common.php');
$firstname = $dbSocket->escapeSimple($firstname);
$lastname = $dbSocket->escapeSimple($lastname);
$email = $dbSocket->escapeSimple($email);
$mobilephone = $dbSocket->escapeSimple($mobilephone);
/* let's generate a random username and password
of length 4 and with username prefix 'guest' */
$rand = createPassword($configValues['CONFIG_USERNAME_LENGTH'], $configValues['CONFIG_USER_ALLOWEDRANDOMCHARS']);
$username = $configValues['CONFIG_USERNAME_PREFIX'] . $rand;
$password = createPassword($configValues['CONFIG_PASSWORD_LENGTH'], $configValues['CONFIG_USER_ALLOWEDRANDOMCHARS']);
/* adding the user to the radcheck table */
$sql = "INSERT INTO ".$configValues['CONFIG_DB_TBL_RADCHECK']." (id, Username, Attribute, op, Value) ".
" VALUES (0, '$username', 'User-Password', '==', '$password')";
$res = $dbSocket->query($sql);
/* adding user information to the userinfo table */
$sql = "INSERT INTO ".$configValues['CONFIG_DB_TBL_DALOUSERINFO']." (username, firstname, lastname, email, mobilephone) ".
" VALUES ('$username', '$firstname', '$lastname', '$email', '$mobilephone')";
$res = $dbSocket->query($sql);
/* adding the user to the default group defined */
if (isset($configValues['CONFIG_GROUP_NAME']) && $configValues['CONFIG_GROUP_NAME'] != "") {
$sql = "INSERT INTO ".$configValues['CONFIG_DB_TBL_RADUSERGROUP']." (UserName, GroupName, priority) ".
" VALUES ('$username', '".$configValues['CONFIG_GROUP_NAME']."', '".$configValues['CONFIG_GROUP_PRIORITY']."')";
$res = $dbSocket->query($sql);
}
include('library/closedb.php');
$status = "success";
} else {
$status = "fieldsFailure";
}
} else {
$status = "captchaFailure";
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>User Sign-Up</title>
<script src="jquery-1.11.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#btnSubmit').click(function() {
var check = check_mobilephone();
check.success(function(data) {
if (data != 1){
$('#register').submit();
return false;
}
});
});
$('#mobilephone').focusout(function() {
var check = check_mobilephone();
check.success(function(data) {
if (data == 1) {
$('.message').html('ชื่ออีเมล์นี้มีคนใช้แล้ว กรุณาเปลี่ยนชื่ออีเมล์ใหม่');
}
});
});
});
function check_mobilephone() {
return $.ajax({
type: 'POST',
data: {mobilephone: $('#mobilephone').val()},
url: 'check_mobilephone.php'
});
}
</script>
</head>
<script src="library/javascript/common.js" type="text/javascript"></script>
<body onLoad="return setFocus();">
<table width="850" height="567" border="0" cellpadding="0" cellspacing="0">
<tr>
<th width="25" height="371" scope="col"> </th>
<th width="800" background="images/Log-in-Page-RYU.jpg" scope="col">
<?php
/*************************************************************************************************************************************************
*
* switch case for status of the sign-up process, whether it's the first time the user accesses it, or rather he already submitted
* the form with either successful or errornous result
*
*************************************************************************************************************************************************/
include("library/daloradius.conf.php");
function showForm() {
include("library/daloradius.conf.php");
//echo " <b>".$configValues['CONFIG_SIGNUP_MSG_TITLE']."</b>
echo "
<form name='signup' action='".$_SERVER['PHP_SELF']."' method='post'>
<table border='0'>
<tr align='left'><td>Name:</td><td> <input type='text' value='' name='firstname' /> </td></tr>
<tr align='left'><td>ID Card:</td><td> <input type='text' value='' name='lastname' /> </td></tr>
<tr align='left'><td>Email address:</td><td> <input type='text' value='' name='email' /> </td></tr>
<tr align='left'><td>Mobilephone:</td><td> <input type='text' value='' name='mobilephone' id='mobilephone'><span class='message'></span> </td></tr>
<tr align='left'><td>Verification code: </td>
<tr align='left'><td><img src='include/common/php-captcha.php'></td>
<td><input name='formKey' type='text' id='formKey' /></td></tr>
<tr align='right'><td><input type='submit' name='submit' value='Register' id='btnSubmit' /><input type='Reset' name='Reset' value='Reset' /> </td></tr>
</table>
</form>
";
}
switch ($status) {
case "firstload":
showForm();
break;
case "success":
echo "
<table border='0'>
<tr align='left'><td>Welcome :".' '.$_POST['firstname']."</br></br></td></td></tr>
<tr align='left'><td>Mobilephone: $mobilephone</br></br></td></tr>
<tr align='left'><td>Click <a href='http://192.168.1.1'><font color='red'>here</font></a><font color='#000000'> to return to the Login page </br>and start your surfing</font></td></tr>
</table>
";
header( "refresh: 8; url=http://192.168.1.1" );
break;
case "fieldsFailure":
echo "<font color='red'>".$configValues['CONFIG_SIGNUP_FAILURE_MSG_FIELDS']."</font><br/><br/>";
showForm();
break;
case "captchaFailure":
echo "<font color='red'><b>".$configValues['CONFIG_SIGNUP_FAILURE_MSG_CAPTCHA']."</b></font><br/><br/>";
showForm();
break;
}
?>
</th>
<th width="25" scope="col"> </th>
</tr>
</table>
<br />
</body>
</html>
check_mobilephone.php
Code (PHP)
<?php
/*
* connection database
*/
$Connect = mysql_connect('localhost', 'radius', 'radius@123') or die('Error connecting to MySQL');
mysql_select_db('itoffsideapp', $Connect) or die('Database sysapp does not exist!');
mysql_query('SET NAMES UTF8');
$mobilephone = isset($_POST['mobilephone']) ? trim($_POST['mobilephone']) : "";
$Query = mysql_query("SELECT * FROM userinfo WHERE mobilephone='{$mobilephone}'");
$Rows = mysql_num_rows($Query);
if($Rows == 1){
echo "1";
}
?>
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2017-05-18 17:52:25 |
By :
karurub |
View :
1229 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
$Connect = mysql_connect('localhost', 'radius', 'radius@123') or die('Error connecting to MySQL');
mysql_select_db('itoffsideapp', $Connect) or die('Database sysapp does not exist!');
mysql_query('SET NAMES UTF8');
$mobilephone = isset($_POST['mobilephone']) ? trim($_POST['mobilephone']) : "";
$Query = mysql_query("SELECT * FROM userinfo WHERE mobilephone='{$mobilephone}'");
$Rows = mysql_num_rows($Query);
if($Rows == 1){
echo "1";
}
ดูตรงนี้ครับ ว่ามีค่าที่ส่งมาเช็คถูกหรือเปล่าครับ
|
|
|
|
|
Date :
2017-05-19 15:30:09 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|