-2

I am getting this error:

Error: INSERT INTO users (username, password, mail, balance, depost1, depost2, depost3) VALUES (test, 4f4dfc9a3bec784d456fafabc725977e, test@test.test, '0', '0', '0', '0') You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '@test.test, '0', '0', '0', '0')' at line 2`.

So, I looked in my syntax, but I can't find any thing that is wrong. Here is my code:

<?php
inculde('config.php');
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
$sql = "INSERT INTO users (username, password, mail, balance, depost1, depost2, depost3)
VALUES ($user, $result, $mail, '0', '0', '0', '0')";
if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Arby Hotel
  • 19
  • 1
  • 4
  • 1
    `$sql = "INSERT INTO users (username, password, mail, balance, depost1, depost2, depost3) VALUES ('$user', '$result', '$mail', '0', '0', '0', '0')";` – Suman Jul 20 '17 at 14:29
  • Missed quotes for $user, $result, $mail – buildok Jul 20 '17 at 14:30
  • this code is totally unsafe to be used in a live environment. Use a prepared statement and `password_hash()/password_verify()` if you want to keep your data safe and db intact. – Funk Forty Niner Jul 20 '17 at 14:36
  • you also used quotes where you most likely don't need them, most likely being integers for `int` column types, whereas the string literals require them to be quoted. – Funk Forty Niner Jul 20 '17 at 14:37
  • you also made a typo => `inculde` which should have read as `include`, but that would have thrown you a completely different error to which wasn't included in the original post, so that IMHO is irrelevant to the post's closure. – Funk Forty Niner Jul 20 '17 at 14:39

3 Answers3

1

You have missed the quotes in query

<?php
    inculde('config.php');
    $conn = new mysqli($servername, $username, $password, $dbname);
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    } 
    $sql = "INSERT INTO users (username, password, mail, balance, depost1, depost2, depost3)
    VALUES ('$user','$result', '$mail', '0', '0', '0', '0')";
    if ($conn->query($sql) === TRUE) {
        echo "New record created successfully";
    } else {
        echo "Error: " . $sql . "<br>" . $conn->error;
    }
    $conn->close();
?>
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Suneel Kumar
  • 1,650
  • 2
  • 21
  • 31
  • 1
    they also made a typo here `inculde` to which you should have spotted, but as I noted in comments under their question, would have been another issue that wasn't part of the original post. I only [edited your answer](https://stackoverflow.com/revisions/45217736/2) about a misplaced quote earlier. – Funk Forty Niner Jul 20 '17 at 14:40
  • @Fred-ii- Agree and Thanks – Suneel Kumar Jul 20 '17 at 14:43
0

Use single quote in value in your Query

$sql = "INSERT INTO users (username, password, mail, balance, depost1, depost2, depost3) VALUES ('$user', '$result', '$mail', '0', '0', '0', '0')"
Sunil Rajput
  • 960
  • 9
  • 19
0

When placing variables directly in a string, they are not automatically wrapped in quotes, even if they are strings.

You will have to change your query to the following:

$sql = "INSERT INTO users (username, password, mail, balance, depost1, depost2, depost3) VALUES ('$user', '$result', '$mail', '0', '0', '0', '0')";
Jerodev
  • 32,252
  • 11
  • 87
  • 108