php和mysql的新手,所以请不要拒绝我的问题。我有从html表单获取输入的数据库,并且我需要一列名为KIASI_KILICHOBAKI的列自动插入两列名为KIASI_ALICHOUZIWA的减法-KIASI_ALICHOTOA。这些是我的代码:
$KIASI_ALICHOUZIWA = $mysqli->real_escape_string($_REQUEST['KIASI_ALICHOUZIWA']);
$KIASI_ALICHOTOA = $mysqli->real_escape_string($_REQUEST['KIASI_ALICHOTOA']);
// Attempt insert query execution
$sql = ("INSERT INTO taarifa (TAREHE,JINA_LA_KWANZA, JINA_LA_MWISHO, NAMBA_YA_SIMU, SHINGO, BEGA, KIFUA, TUMBO, UPANA_WA_MKONO, UREFU_WA_MKONO, HIPS_YA_KOTI, CHINI_UPANA_MKONO, HIPS_SURUALI, PAJA, KIUNO, GOTI, UREFU_WA_SURUALI,CHINI_UPANA_SURUALI, ROUND_SURUALI, UREFU_WA_KIZIBAO, NAFASI_YA_KIZIBAO, HIPS_YA_KIZIBAO, UREFU_WA_MKONO_KIZIBAO , ROUND_YA_MKONO_KIZIBAO, KIASI_ALICHOUZIWA, KIASI_ALICHOTOA, KIASI_KILICHOBAKI) VALUES ('$TAREHE', '$JINA_LA_KWANZA', '$JINA_LA_MWISHO', '$NAMBA_YA_SIMU', '$SHINGO', '$BEGA', '$KIFUA', '$TUMBO', '$UPANA_WA_MKONO','$UREFU_WA_MKONO','$KOTI', '$CHINI_UPANA_MKONO', '$SURUALI', '$PAJA', '$KIUNO', '$GOTI' ,'$UREFU_WA_SURUALI', '$CHINI_UPANA_SURUALI', '$ROUND_SURUALI', '$UREFU_WA_KIZIBAO' , '$NAFASI_YA_KIZIBAO', '$HIPS_YA_KIZIBAO' , '$UREFU_WA_MKONO_KIZIBAO' ,'$ROUND_YA_MKONO_KIZIBAO' , '$KIASI_ALICHOUZIWA' , '$KIASI_ALICHOTOA' , '$KIASI_KILICHOBAKI')");
if($mysqli->query($sql) === true){
header('Location: http://127.0.0.1/dashboard/myindex.php');
} else{
echo "ERROR: Could not be able to execute $sql. " . $mysqli->error;
}
// Close connection
$mysqli->close();
?>
答案 0 :(得分:0)
您尚未创建$ KIASI_KILICHOBAKI变量来保存答案。在插入查询之前添加以下代码
$KIASI_KILICHOBAKI = $KIASI_ALICHOUZIWA - $KIASI_ALICHOTOA;