<?php require_once('db.php'); ini_set('display_errors', 1); ini_set('error_reporting', E_ALL); $link = mysqli_connect($db_host, $db_user, $db_pass, $db_name); if (!$link) { die('<p style="color:red">'.mysqli_connect_errno().' - '.mysqli_connect_error().'</p>'); } $rank1 = $_POST['rank1']; $rank2 = $_POST['rank2']; $cena = $_POST['paymentamount']; $steam = $_POST['steam']; $skype = $_POST['skype']; $nomerz = rand(10000, 99999); $query = mysqli_query($link, "INSERT INTO order_boost (rank1,rank2,cena,steam,skype,nomerz) VALUES ($rank1, $rank2, $cena, $steam, $skype, $nomerz)"); if ($query) { echo "Запрос успешно выполнен!"; } else { echo "Ошибка"; } mysqli_close($link); ?> 

But the request is not executed, "error" is displayed

  • If you speak Russian, then you have written: IF rank1 EXISTS, THEN CREATE A VARIABLE $ rank1 But there is no other way. That is, in cases where rank1 does not exist, the $ rank1 variable will not exist. But while in the sql expression you are trying to use the $ rank1 variable in any situation, even if it is not declared - dakiesse
  • as a solution, declare variables up to if; $ rank1 = $ rank2 = $ cena = $ stream = $ skype = ''; - dakiesse

2 answers 2

The first variant of the cause of the problem — the empty value of the passed parameter — has already been considered.

The second option is that the values ​​for the fields of the string type are not quoted.

Try the code in this form:

 $strSQL = "INSERT INTO order_boost (rank1,rank2,cena,steam,skype,nomerz) VALUES ($rank1, $rank2, $cena, $steam, $skype, $nomerz)"; $query = mysqli_query($link, @strSQL); 

and see what kind of query text is formed in the variable. Try it from the console and see what the server says. In the end, instead of the abstract

 echo "Ошибка"; 

output what the server returned.

  • Error1064: You have an error in your SQL syntax; If you’re the right line , you ’ll find out what you want to use. ” - Satont Worldwide
  • Well, I could correct my typo and write $ strSQL instead of @strSQL in the second statement. - Akina
  • Now the script is not executed: Failed to load resource: the server responded with a status of 500 (Internal Server Error) - Satont Worldwide
  • Well, what kind of query text is formed in a variable - will you show it? UPD: and at the same time what the server returned - in the sense of the MySQL server. - Akina

A POST with a value of $ rank probably comes empty, but the variables in the database do not matter. So it turns out that an empty POST has come - it means that we are not declaring variables, and accordingly there is an error from here. Make a condition if POST came empty $ rank = ""; , well, or do not enter into the database at all, as you like, the main thing is to declare these variables in any case.

  • So maybe the user did not enter anything into these fields, and sent the form like this. You try to remove the record in the database and simply display the data that the form sends to see. echo $ _POST ['rank']; - iKey
  • Now simply the request is not executed. Without any errors. Well, echo "Error" is more precisely executed ;, the request is not fulfilled - Satont Worldwide