简体   繁体   中英

php i can't insert into mysql database but no error

I'm trying to insert data to a MySQL database using PHP but it's not working.

Before I add the code for insert, I checked if the POST is working and getting the data I need from the input.

This is the stored procedure

BEGIN 

    INSERT INTO students
         (
           signatoryid, 
           signatoryname, 
           signatoryposition, 
           signatoryoffice                       

         )
    VALUES 
         ( 
           p_signatoryid, 
           p_signatoryname, 
           p_signatoryposition, 
           p_signatoryoffice                
         ) ; 
END

This is my php to insert data to MySQL. I'm receiving the successful alert but it's not inserting into the database.

<?php 
if (isset($_POST['submit'])){
    $signatory_name = $_POST['sig_name'];
    $signtory_position = $_POST['sig_position'];
    $signatory_office = $_POST['sig_office'];
    require_once 'dbconfig.php';
    try {
    $conn = new PDO("mysql:host=$host;dbname=$dbname",$username, $password);
    $stmt = $conn->prepare("CALL sp_insertsignatory (?), (?), (?), (?)");
    $value = '0001';
    $stmt->bindParam(1, $value, PDO::PARAM_STR, 10); 
    $stmt->bindParam(2, $signatory_name, PDO::PARAM_STR, 30);
    $stmt->bindParam(3, $signtory_position, PDO::PARAM_STR, 30);
    $stmt->bindParam(4, $signatory_office, PDO::PARAM_STR, 30);
    $stmt->execute();
    echo '<script language="javascript">';
    echo 'alert("successful")';
    echo '</script>';
    } catch (PDOException $pe) {
        die("Error occurred:" . $pe->getMessage());
    }   
}
?>

the problem is the table name i used in the stored procedure after fred ii pointed this website http://php.net/manual/en/pdo.error-handling.php and applying it to my code. i receive the error and know what's the problem

$conn = new PDO("mysql:host=$host;dbname=$dbname",$username, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING));
$stmt = $conn->prepare("CALL sp_insertsignatory (?,?,?,?)");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM