简体   繁体   中英

PHP/MySQL Stored procedure issue

I am trying to add to my SQL database using a stored procedure, this procedure should add a unique_id, name, password and email address.

I am using the following code:

    //Enter the valid data into the database
    $username = filter_input(INPUT_POST, 'Username', FILTER_SANITIZE_STRING);
    $encrypted_password = filter_input(INPUT_POST, 'Password', FILTER_SANITIZE_STRING);
    $email = filter_input(INPUT_POST, 'Email', FILTER_SANITIZE_STRING);
    $uuid = uniqid('', true);

    $insertUser = mysqli_query($conn, "Call userInsert('$uuid', '$username','$encrypted_password', '$email')"); 

        if(! $insertUser )
        {
            die('Error: ' . $conn->error);
        }

        else
        {
            echo "Success";
        }

And this is my stored procedure:

$insertIntoUsers = "
CREATE PROCEDURE userInsert(unique_id VARCHAR(23), name VARCHAR(50), encrypted_password VARCHAR(80), email VARCHAR(50))
BEGIN
INSERT INTO users(unique_id, name, encrypted_password,email) values(unique_id, name,encrypted_password,email);
END";

I want it to take four field but I get the following error when I try to sign up

Error: Incorrect number of arguments for PROCEDURE users.userInsert; expected 3, got 4

Anyone know whats causing this? Saying it only wants three arguments, but I have specified four?

managed to sort it

I had the same procedure stored before with 3 arguments, when I added the fourth argument, it never updated, so I dropped the procedure first using:

drop procedure users.userInsert;

and ran the program again, everything worked then

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