mysql-php INSERT INTO not working

2019-09-01 03:45发布

问题:

i am trying to insert to a table and get the ID of the new row.

$mysqli = new mysqli("localhost", "dbuser", "dbpass", "dbname");

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

$query = "INSERT INTO table (tbl1,tbl2,tbl3,tbl4,tbl5) VALUES ('".$tbll."','".$tbl2."','".$tbl3."','0.00','".$tbl5."'"; 
$mysqli->query($query);
$id_log = $mysqli->insert_id;
  • id_log is returning 0 no error anywhere in logs
  • on same file i am doing SELECT & UPDATE and all work perfectly

回答1:

You missed a parenthesis here...

$query = "INSERT INTO table (tbl1,tbl2,tbl3,tbl4,tbl5) VALUES ('".$tbll."','".$tbl2."','".$tbl3."','0.00','".$tbl5."')";
                                                           ----------------------------------------------------------^


标签: php mysql mysqli