无法使用php在数据库中插入值

时间:2015-11-23 11:34:28

标签: php mysql mysqli insert mysql-insert-id

因为我试图通过PHP代码在数据库中插入值但它没有工作,也没有给出任何错误。这是我试图执行但未成功的代码。

 <?php
$mysqli = new mysqli("localhost", "admin", "password", "project") or die("couldn't connect to the database");
error_reporting(0);
session_start();
if (!isset($_SESSION["sess_user"])) {
    header("location:index.php");
} else {
    $username = $_SESSION['sess_user'];
    if (isset($_GET['submit'])) {
        if ($_GET['e1'] == "E-LN3465") {
            $productname = $mysqli->real_escape_string($_GET['e1']);
            if ($insert = $db->query("INSERT INTO `cart`(`ID`, `pid`) ((Select `ID` from `users` where `Username`='$username'),(Select `pid` from `product` where `pname`='$productname'))")) {
                $checkQuery = $mysqli->query("INSERT INTO `cart`(`ID`, `pid`) ((Select `ID` from `users` where `Username`='$username'),(Select `pid` from `product` where `pname`='$productname'))");
            }
        }
    }
}
?>

0 个答案:

没有答案