我有一个包含多个字段的表,我想只更新一个相同的ID。我用来更新的代码是下一个
<?php
require('db.php');
mysql_query("SET NAMES 'utf8'");
date_default_timezone_set('UTC');
include("auth.php"); //include auth.php file on all secure pages
$status = "";
if(isset($_POST['new']) && $_POST['new']==1){
$id=$_REQUEST['id'];
$query = "SELECT * from base where `id`='$id'";
$result = mysql_query($query) or die ( mysql_error());
$row = mysql_fetch_assoc($result);
$scantime = date("Y-m-d H:i:s");
$trn_date = date("Y-m-d H:i:s");
$id=$_REQUEST['id'];
$surname =$_REQUEST['surname'];
$name= $_REQUEST['name'];
$company_name=$_REQUEST['company_name'];
$firm= $_REQUEST['firm'];
$visitors= $_REQUEST['visitors'];
$barcode= $_REQUEST['barcode'];
$submittedby = $_SESSION["username"];
$update="update base set `scantime`='$scantime' where `id`='$id'";
mysql_query($update) or die(mysql_error());
}
?>
使用ajax自动完成功能
搜索数据require_once 'config.php';
mysql_query("SET NAMES 'utf8'");
if($_POST['type'] == 'country_table'){
$row_num = $_POST['row_num'];
$surname = $_POST['name_startsWith'];
$query = "SELECT custId,id,name, surname, company_name, firm,barcode,trn_date,scantime FROM base where UPPER(surname) LIKE '".strtoupper($surname)."%'";
$result = mysqli_query($con, $query);
$data = array();
while ($row = mysqli_fetch_assoc($result)) {
$name = $row['barcode'].'|'.$row['surname'].'|'.$row['name'].'|'.$row['company_name'].'|'.$row['firm'].'|'.$row['trn_date'].'|'.$row['scantime'].'|'.$row['id'].'|'.$row['custId'].'|'.$row_num;
array_push($data, $name);
}
echo json_encode($data);
}
将数据填充到输入字段
$('#barcodescanr').autocomplete({
source: function( request, response ) {
$.ajax({
url : 'ajax.php',
dataType: "json",
method: 'post',
data: {
name_startsWith: request.term,
type: 'barcodescanr',
row_num : 1
},
success: function( data ) {
response( $.map( data, function( item ) {
var code = item.split("|");
return {
label: code[0],
value: code[0],
data : item
}
}));
}
});
},
autoFocus: true,
minLength: 0,
select: function( event, ui ) {
var names = ui.item.data.split("|");
$('#name_1').val(names[2]);
$('#company_name_1').val(names[3]);
$('#surname_1').val(names[1]);
$('#firm_1').val(names[4]);
$('#info').val(names[5]);
$('#scanbartime').val(names[6]);
$('#Id').val(names[7]);
$('#custId').val(names[8]);
},
open: function() {
$( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
},
close: function() {
$( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
}
});
我遇到的问题是,当我按提交表单时,它不会更新scantime。 谢谢