我正在尝试使用将从输入框中收集的值添加数据库中列的值。
例如:我目前在一列中有 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() . '';
}
} }
?>