我試圖插入兩個表,但得到這個錯誤PHP〜列數並不在行1匹配值數
下面Error: INSERT INTO provide_help (amount) VALUES (40,000.00) Column count doesn't match value count at row 1`
是我的插入代碼
<?php
session_start(); {
//Include database connection details
include('../../dbconnect.php');
$amount = strip_tags($_POST['cat']);
$field1amount = $_POST['cat'];
$field2amount = $field1amount + ($field1amount*0.5);
$sql = "INSERT INTO provide_help (amount) VALUES ($field1amount)";
if (mysqli_query($conn, $sql))
$sql = "INSERT INTO gh (ph_id, amount) VALUES (LAST_INSERT_ID(), $field2amount)";
if (mysqli_query($conn, $sql))
{
$_SESSION['ph'] ="<center><div class='alert alert-success' role='alert'>Request Accepted.</div></center>";
header("location: PH.php");
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
}
?>
但是當我做一些這樣的事它的工作原理
$sql = "INSERT INTO provide_help (amount) VALUES ($field2amount)";
我只是改變$field1amount
到$field2amount
,但我不希望它這樣,我想也得到$field1amount
值並將其插入
請任何幫助將appriciated,感謝
您可以[SQL注入](http://php.net/manual/en/security.database.sql-injection.php)和應該真正使用[Prepared Statements](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php)而不是連接你的查詢。特別是因爲你沒有逃避用戶輸入!這也可以解決你的逗號問題。 –