我有一个新手问题。 我有查询日期,准备,批准,项目代码,项目名称,品牌名称,总数量,数量 当我在数量上输入10时,php会提示我输入然后按插入所有查询 怎么做?
<form method="post" name="increasing" action="<?php echo "increasing.php?id=$id"; ?>">
<table>
<h3><center>Increasing</center></h3>
<tr><td>Date</td><td>:</td><td><input type="date" name="date" style="width: 180px;"></td></tr>
<tr><td>Prepared By</td><td>:</td><td>
<select name="pre" style="width: 180px;">
<option value="">Prepared By</option>
<?php foreach ($fullname as $fl): ?>
<option><?=$fl?></option>
<?php endforeach; ?>
</select>
</td></tr>
<tr><td>Approved By</td><td>:</td><td>
<select name="app" style="width: 180px;">
<option value="">Approved By</option>
<?php foreach ($fullname as $fl): ?>
<option><?=$fl?></option>
<?php endforeach; ?>
</select>
</td></tr>
<tr><td>Itemcode</td><td>:</td><td><input type="text" name="itemcode" required="required" disabled="disabled" value="<?php echo $itemcode; ?>"></td></tr>
<tr><td>Itemname</td><td>:</td><td><input type="text" name="itemname" required="required" disabled="disabled" value="<?php echo $itemname; ?>"/></td></tr>
<tr><td>Brandname</td><td>:</td><td><input type="text" name="brandname" required="required" disabled="disabled" value="<?php echo $brandname; ?>"/></td></tr>
<tr><td>Total Quantity</td><td>:</td><td><input type="text" name="brandname" readonly="readonly" value="<?php echo $quantity; ?>"/></td></tr>
<tr><td>Quantity</td><td>:</td><td><input type="number" name="quantity" value=""/></td></tr>
<tr><td></td><td></td><td><input type="hidden" name="quantity1" value="<?php echo $quantity; ?>"></td></tr>
<tr><td></td><td></td><td><input type="submit" name="submit" class="myButton" value="Save"/></td></tr>
</table>
</form>
if(isset($_POST['submit'])){
$id = $_GET['id'];
$old = $_POST['quantity'];
$new = $_POST['quantity1'];
$total = $old + $new;
$uiqry = $mysqli->prepare("UPDATE table_inventory SET quantity = ? WHERE id = ?");
$uiqry->bind_param('ii', $total,$id);
$uiqry->execute();
$uiqry->close();
}
echo "<script>alert('Add');</script>";
echo "<script>window.open('inventory.php', '_self');</script>";
TIA。
答案 0 :(得分:1)
在html
中添加此行<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
HTML
<input type="text" name="date " value=""/>
<input type="text" name="prepared" value=""/>
<input type="text" name="approved" value=""/>
<input type="text" name="itemname" value=""/>
<input type="text" name="itemcode" value=""/>
<input type="text" name="totalquantity" value=""/>
<input type="text" name="quantity" value=""/>
Jquery的
$("input[name=quantity]").change(function(e){
if($(this).val() != "")
{
alert("You have added new data");
var date = $("input[name=date]").val();
var prepared= $("input[name=prepared]").val();
var approved= $("input[name=approved]").val();
var itemname= $("input[name=itemname]").val();
var itemcode= $("input[name=itemcode]").val();
var totalquantity= $("input[name=totalquantity]").val();
var quantity= $("input[name=quantity]").val();
// pass the values to insert using ajax like this
jQuery.post("datains.php", {
date :date ,
prepared:prepared,
approved:approved,
itemname:itemname,
itemcode:itemcode,
totalquantity:totalquantity,
quantity:quantity
}, function(data, textStatus){
if (data == 1)
{
alert("Data inserted");
location.reload();
}
else
{
alert("Data not inserted");
return false;
}
});
}
});
datains.php
// retrive passed values like this
$date= $_POST['date'];
$prepared= $_POST['prepared'];
$approved= $_POST['approved'];
$itemname= $_POST['itemname'];
$itemcode= $_POST['itemcode'];
$totalquantity= $_POST['totalquantity'];
$quantity= $_POST['quantity'];
$con = mysqli_connect("localhost","username","password","dbanme");
$query = //write insert query here;
$result = mysqli_query($con,$query) or die (mysqli_error($con));
if($result)
echo "1";
else
echo "2";