Made a simple registration, as a result of errors does not issue but the database does not update! Here is the code:

<?php $connect = mysqli_connect("localhost", "root", "vertrigo", "my_bd"); if (!$connect) { mysql_error(); } if (isset($_POST['register'])) { $login = $_POST['login']; $pswd = $_POST['pswd']; $pswd_again = $_POST['pswd_again']; $user_name = $_POST['user_name']; $user_surname = $_POST['user_surname']; $user_age = $_POST['user_age']; $user_origin = $_POST['user_origin']; $result = mysqli_query($connect, "INSERT INTO 'users' SET 'login'='$login','password'='$pswd','name'='$user_name','surname'='$user_surname','age'=$'user_age','origin'=$user_origin'") or die(mysql_error()); echo 'YEAH!'; } mysqli_close($connect); 
  • one
    Space for sql injections. Names of tables and fields should not be in single quotes, but in apostrophes. - Visman
  • 2
    I wonder why mysqli , but at the same time mysql_error() - Venta
  • $ result = mysqli_query ($ connect, "INSERT INTO users SET login = $login , password = $pswd , name = $user_name , surname = $user_surname , age = $ user_age , origin = $ user_origin`"); - user225682
  • So, too, nothing has changed. There are apostrophes now. - user225682
  • Is the connection generally established? if (! $ connect) {echo "Error: Unable to connect to MySQL." . PHP_EOL; echo "Error code errno:". mysqli_connect_errno (). PHP_EOL; echo "Error text error:". mysqli_connect_error (). PHP_EOL; exit; } - hardworm

1 answer 1

Try this:

 $result = mysqli_query($connect, "INSERT INTO users (login, password, name, surname, age, origin) VALUES ('$login','$pswd','$user_name','$user_surname','$user_age','$user_origin')"); 
  • It worked. I don’t understand it for me the first time, but it didn’t work and I did it via SET. What’s the mistake, do the brackets stand or apostrophes? - user225682
  • Maybe I did not put spaces before here: users (login, password, name, surname, age, origin). Did it look like this: users (login, password, name, surname, age, origin) or is it not relevant? - user225682
  • one
    @ user225682 in the INSERT INTO 'users' users should either be enclosed in slanting quotes or not quoted in quotes at all. - Alex
  • Yes, @Alex rightly said. The name of the table, as well as the names of the fields of the table are written as is, or wrapped in slanting quotes (an apostrophe, it seems, is called). In general, read the manuals, there are examples and the syntax of the requests is described. And personally, I am more accustomed to doing input with this syntax than through set. Although, through the set, perhaps more clearly, because it is immediately clear which field is being written. - Stanislav