Mysqli插入ID不起作用

时间:2013-12-21 12:01:52

标签: php mysqli

到目前为止,这是我的代码:

$con= mysqli_connect("*********","*********","*********","***********");

if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
    }

$queryorder = 'INSERT INTO `order`
    (`orderone`, `ordertwo`, `orderthree`)
VALUES
        ("'.$one.'","'.$two.'","'.$three.'")';

$result = mysqli_query($con, $queryorder);
        if (!$result) {
        printf("error: %s\n", mysqli_error($con));
        }  

我已经在我的查询后尝试了以下“mysqli_insert_id();”

$orderid = mysqli_insert_id();

并进行了var转储以查看“$ orderid”的值,但我一直收到NULL

var_dump($orderid);

我做错了什么?

谢谢!

2 个答案:

答案 0 :(得分:2)

语法错误

1:将VALUE更改为VALUES

2:包括半结肠

$queryorder = "INSERT INTO `order`(`orderone`, `ordertwo`, `orderthree`) VALUES

----------------------------------------------- -------------------------------------------------- -------------------------- ^

        ('$one','$two','$three')";

另外 更改

if (false === $result) {
        printf("error: %s\n", mysqli_error($con));
        }  

if (!$result) {
        printf("error: %s\n", mysqli_error($con));
        }  

答案 1 :(得分:1)

你遗漏了一个基本的东西“; 分号加上“ VALUES

$queryorder = "INSERT INTO `order`
(`orderone`, `ordertwo`, `orderthree`) VALUES ('$one','$two','$three')";