R e y 發問時間: 電腦與網際網路程式設計 · 3 年前

表單送出無法連結到資料庫?

function insert_goods()

{

global $mysqli;

$goods_title = $mysqli->real_escape_string($_POST['goods_title']);

$goods_price = $mysqli->real_escape_string($_POST['goods_price']);

$goods_in = $mysqli->real_escape_string($_POST['goods_in']);

$goods_out = $mysqli->real_escape_string($_POST['goods_out']);

$goods_total = $mysqli->real_escape_string($_POST['goods_total']);

$sql = "INSERT INTO `goods` (`goods_title`, `goods_price`, `goods_in`, `goods_out`, `goods_total`) VALUES ('{$goods_title}', '{$goods_price}', '{$goods_in}', '{$goods_out}','0'})";

$mysqli->query($sql) or die($mysqli->connect_error);

$goods_sn = $mysqli->insert_id;

return $goods_sn;

}

1 個解答

評分
  • John
    Lv 7
    3 年前
    最佳解答

    如果 global $mysqli; 用得正確的話,就移除多餘的 "}" '0'})";

    $sql = "INSERT INTO `goods` (`goods_title`, `goods_price`, `goods_in`, `goods_out`, `goods_total`) VALUES ('{$goods_title}', '{$goods_price}', '{$goods_in}', '{$goods_out}','0')";

還有問題?馬上發問,尋求解答。