0

I wrote this prepared statment to send data from php to my localhost

         $stmt = $conn->prepare("INSERT INTO info VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
          if ( false===$stmt ) {echo '<script type="text/javascript">alert("false prepeared statment '.htmlspecialchars($conn->error).'");</script>';}
         try{
         $rc = $stmt->bind_param("ssssssssssssssssssss", 'f', '$name1', '$name2', '$name3', '$lastname', '$mother', '$bornplace',
            '$phone', '$empTitle', '$school', '$lastDegree', '$lastSpeciality', '$lastUniversity', '$lastCollege',
             '$subject', '$nextSpeciality', '$nextSubSpeciality', '$nextDepartment', '$nextCollege', '$nextUniversity');
         }catch(Exception  $er){
             echo('err: '.$er->getMessage());
         }

          $rc = $stmt->execute();
          if ( false===$rc ) {echo '<script type="text/javascript">alert("false excute '.htmlspecialchars($stmt->error).'");</script>';}
          $stmt->close();
          $conn->close();

When I run the program, the execution "freeze" when it reach the bind_param line, with no error message or warning. When I comment the bind_param line, the program execution dosen't "freeze" and contincue to the next lines, and gives me the error message "No data supplied for parameters in prepared statement". Notice I made the variable names (in the bind_param) as a string to make sure the problem is not in the value of the variables. And the try catch statement didn't work either. Moreover, when I put some error in the (prepare) line, it shows me the error. But when I put error in (bind_param) line, it just keep freezing! Notice the localhost showing all the errors in all lines normally. But when it comes to this bind_param it doesn't work as expected. I tried a different table with 3 variables, and there were no problem!

ZoZoZo
  • 1
  • 2
  • SIde note: quotes around your variable names make them those exact strings and not their values. `$name1` would supply the value of the variable, `'$name1'` is literally the string `$name1`. – El_Vanja Mar 19 '21 at 12:09
  • If you are only starting to learn PHP then you should learn PDO instead of mysqli. PDO is much easier and more suitable for beginners. Start here https://phpdelusions.net/pdo & https://websitebeaver.com/php-pdo-prepared-statements-to-prevent-sql-injection – Dharman Mar 19 '21 at 12:29

0 Answers0