0

this code last time i check was working but it now simply does nothing. Creating the connection to the database seems to be working, however when i put mysqli_stmt_execute($stmt2) into an if statement, i see that it never returns true and does not work. With no visible errors given even after checking mysqli_error($conn); i have no idea what is going on. Any help?

 $query = "INSERT INTO TempAcc (FirstName, LastName, Email, Password, Hash)
         VALUES ( ?, ?, ?, ?, ?)";

         $arg1 = $fname;
         $arg2 = $lname;
         $arg3 = $email;
         $arg4 = $pass1;
         $arg5 = $hash;
         $type = "sssss";

        $ini_array = parse_ini_file(realpath(dirname(__FILE__))."/../etc/docs/config.ini");
        $servername = $ini_array['servername'];
        $username = $ini_array['user'];
        $password = $ini_array['pass'];
        $dbname = $ini_array['dbname'];

        $conn = mysqli_connect($servername, $username, $password, $dbname);
        if ($conn->connect_error) {
            exit('An error occured');
        }else{
            print("Connect worked");//always works
        }

             $stmt2 = mysqli_stmt_init($conn);
             mysqli_stmt_prepare($stmt2, $query);
             mysqli_stmt_bind_param($stmt2, $type, $arg1, $arg2, $arg3, $arg4, $arg5);

             print("Hello1");//this prints out!

             if(mysqli_stmt_execute($stmt2)){//this never returns true
                 print("we are in");//this never executes!

             }else{//always goes to else
                 //there are no errors even though it failed
                 echo "<script type='text/javascript'>alert('Did not save');</script>";
             }

edit: fixed and duplicate

DiscreteTomatoes
  • 769
  • 1
  • 14
  • 30
  • `mysqli_error($conn);` //this just not intended to print anything – Your Common Sense Sep 17 '16 at 04:12
  • Also, just curious, what's the point in all these assignments like `$arg1 = $fname;`? Can't you just use $fname right off? – Your Common Sense Sep 17 '16 at 04:15
  • @YourCommonSense even though `mysqli_error($conn);` does not print anything, i am still not getting any errors regardless (`mysqli_error($conn);` is really just a last minute addition just in case). Also my question is not duplicate to what you posted because nowhere in that post does it tell my why `mysqli_error($conn);` is failing – DiscreteTomatoes Sep 17 '16 at 04:21
  • 1
    mysqli_error($conn); never fails. besides, I think you want to know what is wrong with your query, not why mysqli_error($conn); is failing. while the linked answer literally explains what you have to do to be able to get mysqli errors – Your Common Sense Sep 17 '16 at 04:26
  • 1
    @YourCommonSense you are right! i used `mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);` and it finally gave me some proper errors that i could solve (the primary key did not have auto increment on). erm.. Thanks :p – DiscreteTomatoes Sep 17 '16 at 04:42
  • 1
    And it is making your code dramatically shorter mind you. You'll never need to check every query's result manually – Your Common Sense Sep 17 '16 at 04:52

0 Answers0