0

I've been spending the last hour trying to research why my SQL will not update to my database with INSERT INTO. I have tried to do my research as to why it is not working but have not come up with an answer.

Some things I have tried are:

Echoing the $query variable to make sure everything is printing to mysqli_query as wanted

Making sure the database is responsive (i can fetch info just not add info)

Trying with accents and without `

Double checking my typos

Is this something obvious or have I just not stumbled upon my error yet?

<?php
$link = mysqli_connect("localhost", "cl14-users-q36", "********", "cl14-users-q36");
if (mysqli_connect_error()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
} 
$query = "INSERT INTO `users`(`id`, `email`, `password`) VALUES(`3`, `new@yahoo.com`, `password`)";
mysqli_query($link, $query);
$query = "SELECT * FROM users";
if ($result = mysqli_query($link, $query)) {
    $row = mysqli_fetch_array($result);
    print_r($row);
    echo "Your email is ".$row[1]." and your password is ".$row[2]."!";
}
?>
chris85
  • 23,846
  • 7
  • 34
  • 51
Caleb Bach
  • 162
  • 11
  • 4
    Backticks (accents) are not for strings. You need to quote strings. Backticks are for tables/columns/databases. `id` should be auto-incrementing. If this is going to dynamic data in the future you should parameterize your query and hash the passwords. – chris85 Apr 06 '17 at 19:30
  • 1
    use single quote for string value VALUES('3', 'new@yahoo.com', 'password') – ScaisEdge Apr 06 '17 at 19:32
  • Chris, thank you for that link. The backticks I used in the VALUES should have been string quotations. I would upvote as an answer if I could. – Caleb Bach Apr 06 '17 at 19:34

0 Answers0