Data not stored using prepared statements

后端 未结 1 404
野性不改
野性不改 2021-01-20 13:20

I am just learning to use prepared statements and stuck here. there is no problem with normal method. there is nothing error shown but the data is not stored in database alt

相关标签:
1条回答
  • 2021-01-20 14:18

    I'd suggest that you wrap the entire bind_param & execute with an if condition as the statement will fail to be prepared if there is even a minor issue. In this case I would guess it could be that the types for each variable/field is wrong at some point - probably the image / b part.

    You can echo the type of each using gettype which might help track it down:

    echo gettype($first), gettype($email), gettype($phone),
         gettype($school), gettype($dob), gettype($father), 
         gettype($feereceived), gettype($due), gettype($image);
    
    
    $db = new mysqli("localhost", "root","","learndb");
    
    if ($db->connect_error) {
        die("Connection failed this is the error: " . $db->connect_error);
    }
    
    $stmt = $db->prepare("INSERT INTO studentrecords (`Name`, `email`, `Phone`, `school`,`dob`,`father`,`feereceived`,`due`,`image`) VALUES (?,?,?,?,?,?,?,?,?)");
    
    if($stmt) {
        $stmt->bind_param("ssisssiib",$first,$email,$phone,$school,$dob,$father,$feereceived,$due,$image);
        $stmt->execute();
    } else {
        echo 'Failed to prepare the sql statement';
    }
    
    0 讨论(0)
提交回复
热议问题