how to write procedure to insert data in to the table in phpmyadmin?
106,183
Solution 1
Try this-
CREATE PROCEDURE simpleproc (IN name varchar(50),IN user_name varchar(50),IN branch varchar(50))
BEGIN
insert into student (name,user_name,branch) values (name ,user_name,branch);
END
Solution 2
# Switch delimiter to //, so phpMyAdmin will not execute it line by line.
DELIMITER //
CREATE PROCEDURE usp_rateChapter12
(IN numRating_Chapter INT(11) UNSIGNED,
IN txtRating_Chapter VARCHAR(250),
IN chapterName VARCHAR(250),
IN addedBy VARCHAR(250)
)
BEGIN
DECLARE numRating_Chapter INT;
DECLARE txtRating_Chapter VARCHAR(250);
DECLARE chapterName1 VARCHAR(250);
DECLARE addedBy1 VARCHAR(250);
DECLARE chapterId INT;
DECLARE studentId INT;
SET chapterName1 = chapterName;
SET addedBy1 = addedBy;
SET chapterId = (SELECT chapterId
FROM chapters
WHERE chaptername = chapterName1);
SET studentId = (SELECT Id
FROM students
WHERE email = addedBy1);
SELECT chapterId;
SELECT studentId;
INSERT INTO ratechapter (rateBy, rateText, rateLevel, chapterRated)
VALUES (studentId, txtRating_Chapter, numRating_Chapter,chapterId);
END //
//DELIMITER;
Solution 3
This method work for me:
DELIMITER $$
DROP PROCEDURE IF EXISTS db.test $$
CREATE PROCEDURE db.test(IN id INT(12),IN NAME VARCHAR(255))
BEGIN
INSERT INTO USER VALUES(id,NAME);
END$$
DELIMITER ;
Comments
-
Harjeet Jadeja almost 2 years
I have created table as below:
student: +----+------+-----------+--------+ |uid | name | user_name | branch | +----+------+-----------+--------+ | | | | | +----+------+-----------+--------+
I want to insert data in to the table using procedure.
the procedure which i wrote is:
create procedure add(in_name varchar(50),in_user_name varchar(50),in_branch varchar(50))
begin
insert into student (name,user_name,branch) values (in_name ,in_user_name,in_branch);
end; -
Harjeet Jadeja over 11 yearsthanks.,its working well. at the time of call i just need to pass the values? exmp:
call simpleproc ('hatjeet','jadeja','i.s.e')
-
Harjeet Jadeja over 11 yearsbut when i am trying that is gives me below error:
#1054 - Unknown column 'in_name' in 'field list'
-
Anthony Rutledge over 8 years@SureshKamrushi Can a MySQL prepared statement be use inside of this stored procedure to insert the row, or would that make everything break? I am playing around trying to do this, but it does not work. No errors. No records inserted. Just wondering. Thanks.
-
posfan12 over 3 yearsIs a procedure like this protection against basic SQL injection attempts?