-1

我正在尝试使用将从输入框中收集的值添加数据库中列的值。

例如:我目前在一列中有 500,我想将 500 添加到从表单(文本框)检索到的新值。

这是我的代码

<?php
     if (isset($_SESSION['user'])) {  
$author = $_SESSION['user'];
//echo $author;
// check if posted is sent   

if (isset($_POST['input'])) {
if (empty($_POST['name']) || empty($_POST['quantity'])) {
echo '<h4 class="alert_info">You Have Not Entered Any Value</h4>';
}      
else {
// retrievings foms data and declaring them as functions
$name = $_POST['name'];
$quantity = $_POST['quantity'];  
$amount = $_POST['amount'];
$category = $_POST['theItems'];    


// Allow apostrophe
$name2 = mysql_real_escape_string($name);
$quantity2 = mysql_real_escape_string($quantity);
$amount2 = mysql_real_escape_string($amount);
$category2 =  mysql_real_escape_string($category);
// inserting the posts 
$insert = "REPLACE INTO drinks SET
name='".$name2."', quantity=' ".$quantity2." ', amount=' ".$amount2." ', category=' ".$category2." ', date=CURDATE()";
if (@mysql_query($insert)) {
echo '<h4 class="alert_info">Drinks added</h4>';
} else {
echo 'Error adding event: ' .
mysql_error() . '';
}
} }
?>
4

3 回答 3

3

我想你正在寻找这样的东西?

<?php
$val = $_POST['quantity'];
$query = "UPDATE drinks SET quantity= quantity + $val WHERE id={put current id here}";
$result = mysql_query($query);
?>
于 2013-03-30T07:59:14.797 回答
1

使用SELECT查询从列中提取当前值,将该值添加到您从文本框中收到的值,然后UPDATE使用新值。

于 2013-03-30T07:53:23.073 回答
0

你可以这样做:

update tableName set columnName = columnName+1
于 2013-03-30T07:55:18.643 回答