php insert语句不在mysql中插入数据

时间:2015-08-03 18:14:33

标签: php mysql database

我试图在mysql数据库中插入通过html表单发布的表单数据。 不幸的是它不起作用。它给了我以下错误。

  

错误:无法执行INSERT INTO orderorder_idcat_idp_idtop_idtime_order,{{ 1}},totaltable_idqty)VALUES(默认值,'1','1',1','2015-08-03 19:57:46', '1000', '1', '2', 'X-大')。您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以便在'','2015-08-03 19:57:46','1000','1','2','X-large'附近使用正确的语法)'在第1行“

这是一个PHP代码。

PHP

size

任何建议或代码都有帮助。在此先感谢:)

1 个答案:

答案 0 :(得分:0)

数字不需要单引号。 pid变量缺少$符号。现在试试。

<?php
include("db_connect.php");
if (!get_magic_quotes_gpc()) {
    $flavor = addslashes($_POST['sel']);
    $topping = addslashes($_POST['top']);
    $size = addslashes($_POST['sizes']);
} else {
    $flavor = $_POST['sel'];
    $topping = $_POST['top'];
    $size = $_POST['sizes'];
}
$qty = $_POST['qty'];
$pid = "SELECT p_id FROM product where name ='" . $flavor . "'";
$result = mysqli_query($link, $pid);
while ($row = mysqli_fetch_array($result)) {
    $res = $row['p_id'];
}
$tid = "select top_id from toppings where type='" . $topping . "'";
$re = mysqli_query($link, $tid);

while ($r = mysqli_fetch_array($re)) {
    $e = $r['top_id'];
}
$abc = "select XL_price from product where name= 'Chicken Fajita'";
$abcd = mysqli_query($link, $abc);

while ($rows = mysqli_fetch_array($abcd)) {
    $resul = $rows['XL_price'];
}

$d = date("Y-m-d H:i:s");
$sql = "INSERT INTO `order`( `cat_id`, `p_id`, `top_id`, `time_order`, `total`, `table_id`, `qty`, `size`) 
        VALUES(1, " . $res . ", " . $e . ", '" . $d . "', " . $resul . ", 1, " . $qty . ", " . $size . ")";