我有問題插入到我的數據庫中我認爲這是當我嘗試將我的prdocutPrice字符串或股票字符串轉換爲十進制和int值。我很確定我正在做其他權利,有人可以爲我確認嗎?將項目插入數據庫
<?php
if (isset($_POST['addSubmitted'])) {
$errors = array();
require_once ('mysql_connect.php');
//This gets all the other information from the form
$name=$_POST['productName'];
$description=$_POST['productDescription'];
$price= floatval($_POST['productPrice']);
$stock= intval($_POST['productStock']);
if (empty($errors)) {
//Writes the information to the database
mysql_query("INSERT INTO products (name, description, price, stock) VALUES ($name, $description, $price, $stock)");
$result = mysql_query($query);
if (mysql_affected_rows() == 1) {
// Show thank you message
echo '<span style="color:green;">Your product has been added.</span>';
} else {
echo '<font color="red">We were unable to add your product to the database.</font>';
}
} else {
echo '<font color="red"><h3>Error!</h3>
The following error(s) occured:<br /></font>';
foreach ($errors as $msg) {
echo " - <font color=\"red\">$msg</font><br />\n";
}
}
}
?>
+1更快的答案和找到雙'mysql_query()' – 2012-04-28 16:28:15
ooo mysql_error()多數民衆贊成在方便!感謝您花時間給我一個這麼好的答案! – Anicho 2012-04-28 16:42:34
在$查詢結束時你有一個額外的')' – Anicho 2012-04-28 16:43:59