0

I have to insert datas using stored procedure in mysql.Here is my SP and function call to that SP.But I can't insert values using them. Can you please verify and give me what to do? SP is:

delimiter ; ;

DROP PROCEDURE IF EXISTS sp_insertUserDetails ; ;
CREATE PROCEDURE sp_insertUserDetails( ) 
BEGIN 
      INSERT INTO tbl_userDetails
       ( strEmail,bitAllowClicktoFBProfile,bitIsAbbreviateLastName, strAboutMe )
VALUES ($strEmail, $bitAllow, $bitAbbreviate, $strAbout);
END

Call to this SP from php file:

$query = mysql_query("CALL sp_insertUserDetails($strEmail, $bitAllow, $bitAbbreviate, $strAbout)");
1
  • 2
    change delimiter value and try Commented Nov 16, 2011 at 5:08

2 Answers 2

1

You dont define any arguments to your SP - did you even try call it straight from SQL eg:

mysql> call sp_insertUserDetails("foo", "bar", "dave", "str");
ERROR 1318 (42000): Incorrect number of arguments for PROCEDURE test.sp_insertUserDetails; expected 0, got 4

You need something like this

DROP PROCEDURE IF EXISTS sp_name;
delimiter ;;
CREATE PROCEDURE sp_name(fname varchar (20), lname varchar(20))
BEGIN
   SELECT concat('Hello ', fname, ',', lname);
END
;;
delimiter ;
Sign up to request clarification or add additional context in comments.

Comments

0

just do this

HERE i am assuming that all values are in varchar

DELIMITER //

DROP PROCEDURE IF EXISTS sp_insertUserDetails; 
CREATE PROCEDURE sp_insertUserDetails( 
 IN strEmail varchar(255), 
 IN bitAllow varchar(255),
 IN bitAbbreviate varchar(255),
 IN strAbout varchar(255)
) 
BEGIN 
      INSERT INTO tbl_userDetails
       ( strEmail,bitAllowClicktoFBProfile,bitIsAbbreviateLastName, strAboutMe )
VALUES (strEmail, bitAllow, bitAbbreviate, strAbout);
END //
DELIMITER ;

and call like this

mysql_query( CALL sp_insertUserDetails($strEmail, $bitAllow, $bitAbbreviate, $strAbout) )

1 Comment

Sorry diEcho, Now it is error free. But insertion into the table is not working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.