I have a simple HTML form and some php variables as follows to submit book details to a MySQL table named Book using submit method. clcode is a auto increment field.
$isbn =$_POST["isbn"];
$bno =$_POST["b_no"];
$bname =$_POST["b_name"];
$qty =$_POST["qty"];
$price =$_POST["price"];
And need to insert records depending on the qty. eg:- If a qty=2, It needs to execute the insert query twice (Should be inserted 2 same records with auto increment clcodes). If a qty=5, It needs to execute the insert query 5 times (Should be inserted 5 same records with auto increment clcodes) and so on... I used a stored procedure and the following SQL query to do that.
$query ="CREATE PROCEDURE myproc()
BEGIN
DECLARE i int DEFAULT 0;
DO
INSERT INTO book (isbn, b_no, b_name, qty, price) VALUES ('$isbn', '$bno', '$bname', '$qty', '$price');
SET i = i + 1;
WHILE i < $qty;
END WHILE;
END";
$result = mysql_query($query) or die ( mysql_error());
But it is return a syntax error. I can not uderstand what I am going wrong. Pls. anyone can help me...? Tnx.