Data from the form is not sent to MySQL database. Here is the code:

<?php if (isset($_POST['login']) && isset($_POST['password']) && isset($_POST['email']) && isset($_POST['phone']) && isset($_POST['token'])){ $login = $_POST['login']; $password = $_POST['password']; $email = $_POST['email']; $phone = $_POST['phone']; $token = $_POST['token']; $db_host = ''; $db_user = ''; $db_password = ''; $db_base = ''; $db_table = ''; $mysqli = new mysqli($db_host,$db_user,$db_password, $db_base); if ($mysqli->connect_error) { die('Ошибка : ('. $mysqli->connect_error .') '. $mysqli->connect_error); } $result = $mysqli->query("INSERT INTO ".$db_table." (login,password,email,phone,token) VALUES ('$login','$password','$email','$phone','$token')"); if ($result == true){ echo "Информация занесена в базу данных"; }else{ echo "Информация не занесена в базу данных"; } } mysqli_close($mysqli); ?> 

At the output gives "Information is not entered in the database"

  • one
    Now you need to open the manual php.net/manual/ru/mysqli.query.php , find how to display the text of the error, display it and realize. - u_mulder 1:32 pm
  • Thank you. I had no experience with PHP and MySQL before, and I undertook to google. For some reason I thought that PHP itself would create a table in the selected database if it does not exist :) - lexani42
  • Try this: $ result = $ mysqli-> query ("INSERT INTO". $ Db_table. "(Login, password, email, phone, token) VALUES ('{$ login}', '{$ password}', '{ $ email} ',' {$ phone} ',' {$ token} ') "); - Nilsan
  • No, he won’t create how he knows what fields you need there) - u_mulder 1:43 pm
  • By the way, since you start working with php / mysql, I recommend working with prepared expressions right away, this will save you a lot of problems. - u_mulder

1 answer 1

 $db_host = ''; $db_user = ''; $db_password = ''; $db_base = ''; $db_table = ''; 

not only is this and single quotes here

 $result = $mysqli->query("INSERT INTO ".$db_table." (login,password,email,phone,token) VALUES ('$login','$password','$email','$phone','$token')"); 

this place is necessary

  $result = $mysqli->query("INSERT INTO ".$db_table." (`login`,`password`,`email`,`phone`,`token`) VALUES (".$login.",".$password.",".$email.",".$phone.",".$token.")"); 
  • We thought at least a little before writing. INSERT INTO table (login) VALUES (Username) - is this your correct request? - u_mulder
  • "this place" is not necessary. There is no difference between 'and ". The answer would make sense if I had written, for example, VALUES (' $ login"). And so the answer, though mediocre, has already been given - lexani42
  • quotation marks are converted to string type, but double quotes allow reading the value of variables inside quotation marks a 'just string - Aram77778