|
|
|
ทำให้กล่องข้อความเช็คข้อมูลซ้ำ อยู่หน้าเดียวกันกับ หน้ากรอกแบบฟอร์ม |
|
|
|
|
|
|
|
alert เสร็จแล้วก็ return false ครับ
|
|
|
|
|
Date :
2017-02-17 19:11:36 |
By :
เด็กหัวกะโป๊ก |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
คือตอนนี้โค้ดผมเป็นแบบนี้ครับ
หน้าสำหรับกรอกข้อมูล
<!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=utf-8" />
<title>Untitled Document</title>
<script src="file:///C|/xampp/htdocs/bic/SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<link href="file:///C|/xampp/htdocs/bic/SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Datepicker - Select a Date Range</title>
<link rel="stylesheet" href="../jquery-ui-1.12.1.custom/jquery-ui-1.12.1.custom/jquery-ui.css">
<script src="../jquery-ui-1.12.1.custom/jquery-ui-1.12.1.custom/external/jquery/jquery.js"></script>
<script src="../jquery-ui-1.12.1.custom/jquery-ui-1.12.1.custom/jquery-ui.js"></script>
<script>
$( function() {
var dateFormat = "yy-mm-dd",
from = $( "#start" )
.datepicker({
defaultDate: "+1w",
changeMonth: true,
dateFormat : 'yy-mm-dd',
numberOfMonths: 1
})
.on( "change", function() {
to.datepicker( "option", "minDate", getDate( this ) );
}),
to = $( "#finished" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
dateFormat : 'yy-mm-dd',
numberOfMonths: 1
})
.on( "change", function() {
from.datepicker( "option", "maxDate", getDate( this ) );
});
function getDate( element ) {
var date;
try {
date = $.datepicker.parseDate( dateFormat, element.value );
} catch( error ) {
date = null;
}
return date;
}
} );
</script>
</head>
<script language="JavaScript">
var HttPRequest = false;
function doCallAjax() {
HttPRequest = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
HttPRequest = new XMLHttpRequest();
if (HttPRequest.overrideMimeType) {
HttPRequest.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
HttPRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
HttPRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!HttPRequest) {
alert('Cannot create XMLHTTP instance');
return false;
}
var url = 'check.php';
var pmeters = "ip=" + encodeURI( document.getElementById("ip").value);
HttPRequest.open('POST',url,true);
HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
HttPRequest.setRequestHeader("Content-length", pmeters.length);
HttPRequest.setRequestHeader("Connection", "close");
HttPRequest.send(pmeters);
HttPRequest.onreadystatechange = function()
{
if(HttPRequest.readyState == 3) // Loading Request
{
document.getElementById("mySpan").innerHTML = "..";
}
if(HttPRequest.readyState == 4) // Return Request
{
if(HttPRequest.responseText == 'Y')
{
window.location = 'check.php';
}
else
{
document.getElementById("mySpan").innerHTML = HttPRequest.responseText;
}
}
}
}
</script>
<body>
<p> </p>
<h2 style="text-align: center"><strong>ฟอร์มยื่นคำร้องขอ IP Address</strong></h2>
<form id="form2" name="form2" method="post" action="add.php">
<table width="500" border="0" align="center">
<tr>
<td width="184" height="38">Reguester name</td>
<td width="14" align="center">:</td>
<td width="319"><label for="re_name"></label>
<input type="text" name="re_name" id="re_name" /></td>
</tr>
<tr>
<td height="38">IP Address</td>
<td align="center">:</td>
<td><label for="textfield"></label>
<label for="ip"></label>
<span id="sprytextfield1">
<input type="text" name="ip" id="ip" OnChange="JavaScript:doCallAjax();"/>
<span id="mySpan"></span></span></td>
</tr>
<tr>
<td height="40">Computer name</td>
<td align="center">:</td>
<td><label for="com_name"></label>
<input type="text" name="com_name" id="com_name" /></td>
</tr>
<tr>
<td height="39">Mac address</td>
<td align="center">:</td>
<td><label for="mac"></label>
<input type="text" name="mac" id="mac" /></td>
</tr>
<tr>
<td height="35">From</td>
<td align="center">:</td>
<td><label for="textfield5"></label>
<input type="text" name="start" id="start" /></td>
</tr>
<tr>
<td height="40">To</td>
<td align="center">:</td>
<td><label for="textfield6"></label>
<input type="text" name="finished" id="finished" /></td>
</tr>
<tr>
<td>Remark</td>
<td align="center">:</td>
<td><label for="remark"></label>
<label for="remark"></label>
<textarea name="remark" id="remark" cols="45" rows="5"></textarea></td>
</tr>
</table>
<p align="center">
<input type="submit" name="button" id="button" value="บันทึก" />
<input type="reset" name="button2" id="button2" value="ยกเลิก" />
</p>
</form>
<script type="text/javascript">
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");
var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2");
var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3");
</script>
</body>
</html>
หน้าสำหรับ save
<!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=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<p>
<?php
$re_name=$_POST['re_name'];
$ip=$_POST['ip'];
$com_name=$_POST['com_name'];
$mac=$_POST['mac'];
$start=$_POST['start'];
$finished=$_POST['finished'];
$remark=$_POST['remark'];
mysql_connect("localhost","root","1234");
mysql_select_db("bic");
mysql_query("SET NAMES UTF8");
$sql = "SELECT * FROM reguester_ip WHERE ip = '".$_POST["ip"]."' ";
$rc = mysql_query($sql);
if (!filter_var($ip, FILTER_VALIDATE_IP) === true) {
echo "<script language=\"JavaScript\">";
echo "alert('$ip is not a valid IP address');";
echo "window.history.go(-1);</script>";
exit;
}
$sql = "SELECT * FROM reguester_ip WHERE ip = '".$_POST["ip"]."' ";
$rc = mysql_query($sql);
$objResult = mysql_fetch_array($rc);
if($objResult)
{
echo "<script language=\"JavaScript\">";
echo "alert('IP Address นี้มีอยู่แล้ว ไม่สามารถบันทึกข้อมูลได้.');";
echo "window.history.go(-1);</script>";
exit;
}
else
{
$sql="INSERT INTO reguester_ip(re_name,ip,com_name,mac,start,finished,remark)
VALUES('$re_name','$ip','$com_name','$mac','$start','$finished','$remark')";
$rc=mysql_query($sql);
if($rc=="1"){
echo "<script language=\"JavaScript\">";
echo "alert('บันทึกข้อมูลเรียบร้อยแล้ว');";
echo "window.location='list.php'</script>";
}else{
echo "<script language=\"JavaScript\">";
echo "alert('ไม่สามารถบันทึกข้อมูลได้');";
echo "window.location='list.php'</script>";
}
}
mysql_close();
?>
</p>
<p align="center"><a href="list.php">ดูข้อมูลการยื่นคำขอ IP</a></p>
</body>
</html>
|
|
|
|
|
Date :
2017-02-17 22:53:27 |
By :
puruther |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผมอยากจะให้มันเด้งขึ้นมาที่หน้า กรอกข้อมูลอ่ะครับ
ไม่ใช่หน้า add.php
คือหน้ากรอกข้อมูลผมให้มันลิงค์ไปที่หน้า add.php เมื่อกดบันทึก
หน้าต่างสำหรับเช็คมันเลยไปเป็นอีกลิงค์นึง
ผมอยากให้มันหน้าต่างเช็ค มันขึ้นอยู่ที่หน้ากรอกข้อมูลอ่ะครับ
ช่วยทีนะครับ
|
ประวัติการแก้ไข 2017-02-17 22:57:40
|
|
|
|
Date :
2017-02-17 22:56:45 |
By :
puruther |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ควรจะมี 3 หน้านะครับ 1.ฟอร์ม 2.เช็ค ip ซ้ำ 3. บันทึกข้อมูล
หน้าฟอร์ม
<!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=utf-8" />
<title>Untitled Document</title>
<script src="file:///C|/xampp/htdocs/bic/SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<link href="file:///C|/xampp/htdocs/bic/SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Datepicker - Select a Date Range</title>
<link rel="stylesheet" href="../jquery-ui-1.12.1.custom/jquery-ui-1.12.1.custom/jquery-ui.css">
<script src="../jquery-ui-1.12.1.custom/jquery-ui-1.12.1.custom/external/jquery/jquery.js"></script>
<script src="../jquery-ui-1.12.1.custom/jquery-ui-1.12.1.custom/jquery-ui.js"></script>
<script>
$( function() {
var dateFormat = "yy-mm-dd",
from = $( "#start" )
.datepicker({
defaultDate: "+1w",
changeMonth: true,
dateFormat : 'yy-mm-dd',
numberOfMonths: 1
})
.on( "change", function() {
to.datepicker( "option", "minDate", getDate( this ) );
}),
to = $( "#finished" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
dateFormat : 'yy-mm-dd',
numberOfMonths: 1
})
.on( "change", function() {
from.datepicker( "option", "maxDate", getDate( this ) );
});
function getDate( element ) {
var date;
try {
date = $.datepicker.parseDate( dateFormat, element.value );
} catch( error ) {
date = null;
}
return date;
}
} );
</script>
</head>
<script language="JavaScript">
var HttPRequest = false;
function doCallAjax() {
HttPRequest = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
HttPRequest = new XMLHttpRequest();
if (HttPRequest.overrideMimeType) {
HttPRequest.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
HttPRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
HttPRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!HttPRequest) {
alert('Cannot create XMLHTTP instance');
return false;
}
var url = 'check.php';
var pmeters = "ip=" + encodeURI( document.getElementById("ip").value);
HttPRequest.open('POST',url,true);
HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
HttPRequest.setRequestHeader("Content-length", pmeters.length);
HttPRequest.setRequestHeader("Connection", "close");
HttPRequest.send(pmeters);
HttPRequest.onreadystatechange = function()
{
if(HttPRequest.readyState == 3) // Loading Request
{
document.getElementById("mySpan").innerHTML = "..";
}
if(HttPRequest.readyState == 4) // Return Request
{
if(HttPRequest.responseText == 1)
{
document.getElementById("button1").disabled = true;
alert('IP Address นี้มีอยู่แล้ว ไม่สามารถบันทึกข้อมูลได้.');
}
else
{
document.getElementById("button1").disabled = false;
document.getElementById("mySpan").innerHTML = '<b>✔</b>';
}
}
}
}
</script>
<body>
<p> </p>
<h2 style="text-align: center"><strong>ฟอร์มยื่นคำร้องขอ IP Address</strong></h2>
<form id="form2" name="form2" method="post" action="add.php">
<table width="500" border="0" align="center">
<tr>
<td width="184" height="38">Reguester name</td>
<td width="14" align="center">:</td>
<td width="319"><label for="re_name"></label>
<input type="text" name="re_name" id="re_name" /></td>
</tr>
<tr>
<td height="38">IP Address</td>
<td align="center">:</td>
<td><label for="textfield"></label>
<label for="ip"></label>
<span id="sprytextfield1">
<input type="text" name="ip" id="ip" OnChange="JavaScript:doCallAjax();"/>
<span id="mySpan"></span></span></td>
</tr>
<tr>
<td height="40">Computer name</td>
<td align="center">:</td>
<td><label for="com_name"></label>
<input type="text" name="com_name" id="com_name" /></td>
</tr>
<tr>
<td height="39">Mac address</td>
<td align="center">:</td>
<td><label for="mac"></label>
<input type="text" name="mac" id="mac" /></td>
</tr>
<tr>
<td height="35">From</td>
<td align="center">:</td>
<td><label for="textfield5"></label>
<input type="text" name="start" id="start" /></td>
</tr>
<tr>
<td height="40">To</td>
<td align="center">:</td>
<td><label for="textfield6"></label>
<input type="text" name="finished" id="finished" /></td>
</tr>
<tr>
<td>Remark</td>
<td align="center">:</td>
<td><label for="remark"></label>
<label for="remark"></label>
<textarea name="remark" id="remark" cols="45" rows="5"></textarea></td>
</tr>
</table>
<p align="center">
<input type="submit" name="button" id="button1" value="บันทึก" />
<input type="reset" name="button2" id="button2" value="ยกเลิก" />
</p>
</form>
<script type="text/javascript">
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");
var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2");
var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3");
</script>
</body>
</html>
check.php
<?php
mysql_connect("localhost","root","1234");
mysql_select_db("bic");
mysql_query("SET NAMES UTF8");
$sql = "SELECT * FROM reguester_ip WHERE ip = '".$_POST["ip"]."'";
$rc = mysql_query($sql);
$num = mysql_num_rows($rc);
if($num){
echo 1;
} else {
echo 0;
}
?>
add.php
<!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=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<p>
<?php
$re_name=$_POST['re_name'];
$ip=$_POST['ip'];
$com_name=$_POST['com_name'];
$mac=$_POST['mac'];
$start=$_POST['start'];
$finished=$_POST['finished'];
$remark=$_POST['remark'];
mysql_connect("localhost","root","1234");
mysql_select_db("bic");
mysql_query("SET NAMES UTF8");
$sql="INSERT INTO reguester_ip(re_name,ip,com_name,mac,start,finished,remark)
VALUES('$re_name','$ip','$com_name','$mac','$start','$finished','$remark')";
$rc=mysql_query($sql);
if($rc){
echo "<script language=\"JavaScript\">";
echo "alert('บันทึกข้อมูลเรียบร้อยแล้ว');";
echo "window.location='list.php'</script>";
}else{
echo "<script language=\"JavaScript\">";
echo "alert('ไม่สามารถบันทึกข้อมูลได้');";
echo "window.location='list.php'</script>";
}
?>
</p>
</body>
</html>
|
ประวัติการแก้ไข 2017-02-17 23:44:40
|
|
|
|
Date :
2017-02-17 23:42:03 |
By :
tomrambo |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|