简体   繁体   中英

You have an error in your SQL syntax; and $db->query(ERROR: 1)

I tried to so hard to find a solution for this but in vain. I could insert into the db successfully all the data, but still I get the same problem.

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1

I did escape my variables, added ticks ` to the table, but still the same problem.

$insert = $db->query("INSERT INTO `uploadusers` (uploadusers.uname, uploadusers.phone, uploadusers.mail, uploadusers.lng, uploadusers.path) VALUES ('" . mysqli_real_escape_string($db, $userName) . "', '" . mysqli_real_escape_string($db, $userPhone)."', '" . mysqli_real_escape_string($db, $userMail)."', '" . mysqli_real_escape_string($db, $userLng)."', '" . mysqli_real_escape_string($db, $path)."')");
                if ($db->query($insert)) {
                        echo "New record created successfully";
                    } else {
                        echo "Error: " . $insert . "<br>" . $db->error;
                    }

When I echo $insert gives me '1' and $db->error gives me that error.

The problem here is that you're calling query() twice.

So remove one of them and just do if ($insert)) {

$insert = $db->query("INSERT INTO... ");
    if ($insert) {

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM