|
|
|
ถามเรื่อง Autofill เปลี่ยนจาก SQL เป็น SQLi ไม่ทำงาน |
|
|
|
|
|
|
|
Code (PHP)
<?php
ini_set('display_errors', 1);
error_reporting(~0);
error_reporting( error_reporting() & ~E_NOTICE );
$serverName = "localhost";
$userName = "root";
$userPassword = "";
$dbName = "mydatabase";
$conn = mysqli_connect($serverName,$userName,$userPassword,$dbName);
mysqli_set_charset($conn, "utf8");
$strSQL = "SELECT * FROM customer WHERE 1 AND CustomerID = '".$_POST["sCusID"]."' ";
$objQuery =mysqli_query($conn,$strSQL);
$intNumField = mysqli_num_fields($objQuery);
$resultArray = array();
while($obResult = mysqli_fetch_array($objQuery,MYSQLI_ASSOC))
{
$arrCol = array();
for($i=0;$i<$intNumField;$i++)
{
$arrCol[mysqli_field_name($objQuery,$i)] = $obResult[$i];
}
array_push($resultArray,$arrCol);
}
mysqli_close($conn);
echo json_encode($resultArray);
?>
Code (PHP)
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ThaiCreate.Com</title>
<script type="text/javascript" src="jquery-1.4.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#txtCustomerID").change(function(){
$.ajax({
url: "returnCustomer2.php" ,
type: "POST",
data: 'sCusID=' +$("#txtCustomerID").val()
})
.success(function(result) {
var obj = jQuery.parseJSON(result);
if(obj == '')
{
$('input[type=text]').val('');
}
else
{
$.each(obj, function(key, inval) {
$("#txtCustomerID").val(inval["CustomerID"]);
$("#txtName").val(inval["Name"]);
$("#txtEmail").val(inval["Email"]);
$("#txtCountryCode").val(inval["CountryCode"]);
$("#txtBudget").val(inval["Budget"]);
$("#txtUsed").val(inval["Used"]);
});
}
});
});
});
</script>
</head>
<body>
<h2>jQuery Auto fill ดึงข้อมูลอัตโนมัติ</h2>
<table width="302" border="1">
<tr>
<td width="104">CustomerID</td>
<td width="153"><input type="text" id="txtCustomerID" name="txtCustomerID" size="5"></td>
</tr>
<tr>
<td>Name</td>
<td><input type="text" id="txtName" name="txtName" size="20"></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" id="txtEmail" name="txtEmail" size="25"></td>
</tr>
<tr>
<td>CountryCode</td>
<td><input type="text" id="txtCountryCode" name="txtCountryCode" size="2"></td>
</tr>
<tr>
<td>Budget</td>
<td><input type="text" id="txtBudget" name="txtBudget" size="5"></td>
</tr>
<tr>
<td>Used</td>
<td><input type="text" id="txtUsed" name="txtUsed" size="5"></td>
</tr>
</table>
</body>
</html>
เปลี่ยนไช้ SQLI แล้วมันไม่ทำงานครับ...ไม่รู้ทำไม..
Tag : PHP, jQuery
|
|
|
|
|
|
Date :
2016-04-01 14:01:43 |
By :
dongjar |
View :
1083 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (JavaScript)
$("#txtCustomerID").change(function(){
$.ajax({
url: "returnCustomer2.php" ,
type: "POST",
data: 'sCusID=' +$("#txtCustomerID").val()
})
.success(function(result) {
var obj = jQuery.parseJSON(result);
if(obj == '')
{
$('input[type=text]').val('');
}
else
{
$.each(obj, function(key, inval) {
$("#txtCustomerID").val(inval["CustomerID"]);
$("#txtName").val(inval["Name"]);
$("#txtEmail").val(inval["Email"]);
$("#txtCountryCode").val(inval["CountryCode"]);
$("#txtBudget").val(inval["Budget"]);
$("#txtUsed").val(inval["Used"]);
});
}
}).fail(function(rs) {
console.log(rs);
});
});
ดู Error ที่ Log นะครับ
|
|
|
|
|
Date :
2016-04-01 15:49:56 |
By :
geidtiphong |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|