I rummaged through the whole Runet and the Internet didn’t find anything. Maybe they will help me here. Essence does not work last request. He is not satisfied.

<? session_start(); include $_SERVER['DOCUMENT_ROOT'].'/conf/db_connect.php'; $sql = "call get_user_by_user_name('$_POST[username]')"; $get_user = db_query($sql, $link, $_SESSION[mode]); $row = db_fetch($get_user, $_SESSION[mode]); if(!empty($row[user_id])) { header ("location:/reg/regindex.php?error=1"); exit; } if( !empty( $_FILES['avatar']['name'] ) ) { $userAvatar = $_SERVER['DOCUMENT_ROOT'].'/avatars/' .$_POST['username']. basename($_FILES['avatar']['name']); $userAvatarPath = '/avatars/' .$_POST['username']. basename($_FILES['avatar']['name']); if( substr($_FILES['avatar']['type'], 0, 5)=='image' ) { if (!move_uploaded_file($_FILES['avatar']['tmp_name'], $userAvatar)) { header ("location:/reg/regindex.php?error=2"); exit; } } else { header ("location:/reg/regindex.php?error=2"); exit; } } else { unset($userAvatar); unset($userAvatarPath); } $userName = $_POST['username']; $userPassword = $_POST['pw']; $email = $_POST['email']; $userFirstName = $_POST['firstname']; $userLastName = $_POST['lastname']; $birthdate = $_POST['date']; $userName = stripslashes($userName); $userName = htmlspecialchars($userName); $userName = addslashes($userName); $userPassword = stripslashes($userPassword); $userPassword = htmlspecialchars($userPassword); $userPassword = addslashes($userPassword); $userFirstName = stripslashes($userFirstName); $userFirstName = htmlspecialchars($userFirstName); $userFirstName = addslashes($userFirstName); $userLastName = stripslashes($userLastName); $userLastName = htmlspecialchars($userLastName); $userLastName = addslashes($userLastName); $email = stripslashes($email); $email = htmlspecialchars($email); $email = addslashes($email); $userName = trim($userName); $userPassword = trim($userPassword); $userFirstName = trim($userFirstName); $userLastName = trim($userLastName); $email = trim($email); $userName = str_replace("'","'",$userName); $userPassword = str_replace("'","'",$userPassword); $userFirstName = str_replace("'","'",$userFirstName); $userLastName = str_replace("'","'",$userLastName); $email = str_replace("'","'",$email); $sql_two = "call add_user('$userName','$userPassword','$email','$userLastName','$userLastName','$birthdate','$userAvatarPath')"; db_query($sql_two, $link, $_SESSION['mode']); header ("location:/reg/regend.php"); ?> 

If I comment it out

 $sql = "call get_user_by_user_name('$_POST[username]')"; $get_user = db_query($sql, $link, $_SESSION[mode]); $row = db_fetch($get_user, $_SESSION[mode]); 

Everything is working. Otherwise, the opposite. Even the error does not betray if I remove the "or die". None of them work. $ link is a global connection variable, did checks before the last request, the connection does not fall off. There are no problems with him. There is another file, there are two requests in a row

 $tempRow = db_row(db_query("SELECT count(*) FROM view_guest_book", $link, $_SESSION['mode']), $_SESSION['mode']); $result = db_query("call get_entries_gb_per_page('$per_page', '$start')", $link, $_SESSION['mode']); 

Db_query function

 function db_query($query, $link, $conntype) { switch($conntype) { case "sqlb": { $result = mysql_query($query) or die("\nНекорректный SQL запрос >>" . $query); return $result; break; } case "sqlip": { $result = mysqli_query($link, $query) or die("\nНекорректный SQL запрос >>" . $query); return $result; break; } case "sqlio": { $result = $link->query($query) or die("\nНекорректный SQL запрос >>" . $query); return $result; break; } case "pdo": { $result = $link->prepare($query); $result->setFetchMode(PDO::FETCH_NUM); $result->execute() or die("\nНекорректный SQL запрос >>" . $query); return $result; break; } default:break; } } 

db_row is about the same, only functions corresponding to extensions are used there. Yes, and another such moment, before that, another database, and the queries were directly to the tables, and it did not work through procedures. In general, brains boil all nonsense.

  • I did not add about those two consecutive requests. In the order that I wrote, they work, if you swap them, then exactly the same burda. It worked when there were SELECTs, now with Nichrome procedures. - Ilya
  • you would combine these stripslashes, trim, htmlspecialchars, and then you remove the shielding of the stripslashes symbols first and then add, you are mistaken - user33274
  • I did this when I did not know what else could help me. Out of desperation, now I have found the problem, I need to bring the code in order. - Ilya
  • include $ _SERVER ['DOCUMENT_ROOT']. '/ conf / db_connect.php'; and here exactly right? - user33274

1 answer 1

In general, I found the problem, if calling the code in the code, then after them in the code, no request will work. How now only from this disease get rid of. I will describe the problem. If requests are in this order

 $result = mysqli_query($link, "call get_entries_gb_per_page('$per_page', '$start')"); $result_2= mysqli_query($link, "SELECT count(*) FROM view_guest_book"); 

That second request after a call will not work. I do not know what it is connected with. If they change their places, it will work. Obviously, the problem is that the call is called because I have not used them in the code before, but here the need has appeared. Yes, and not the first time I meet this problem, while working with the storage.

UPDATE Problem solved. True, I do not know what it is connected with, who can explain. In general, immediately before executing the query, I insert

 if(mysqli_next_result($link)) mysqli_store_result($link); 

It looks like this:

 if(mysqli_next_result($link)) mysqli_store_result($link); $result = mysqli_query($link, "call get_entries_gb_per_page('$per_page', '$start')"); if(mysqli_next_result($link)) mysqli_store_result($link); $result_2= mysqli_query($link, "SELECT count(*) FROM view_guest_book"); 
  • one
    Add an example that would not be empty chapters and the author will check and choose your option the best - user33274
  • Can anyone explain why this is happening? - Ilya
  • @LenovoID and who is the author? - Ipatiev
  • author Ilya, but I wrote my comment but did not read the name of the answer I gave - user33274