Saturday, 5 November 2016

how to create procedure in XAMPP-MYSQL and how to insert form data to database using Procedure

03:12

(1)FIRST CREATE TABLE   tbl_ext:

SQL>
create table tbl_ext
(id  int primary key auto_increment,
name  varchar(200),
address  varchar(200)
);

======================================================================
INSERT   RECORD INTO DATABASE USING MYSQL PROCEDURE IN PHP:
======================================================================

(2)CREATE PROCEDURE  myinsert():

SQL>

CREATE PROCEDURE  myinsert(IN name varchar(20),IN adds varchar(200))

BEGIN INSERT INTO tbl_ext(name ,address)VALUES(name,adds);

End



(3)CALL PROCEDURE:

SQL>call  myinsert('OMji','VIRAR');

(4)WRITE  CODE  FOR   "insert.html"  file:

<form  action="insert.php"  method="post">
name<input type=text     name=name>
address<input type=text  name=address>
<input type=submit name=submit value="submit">
</form>


(5)WRITE CODE FOR  "insert.php"  file:

<?php
$con=mysql_connect("Localhost","root","");
mysql_select_db('abhi',$con);
$name=$_POST['name'];
$city=$_POST['address'];
$sql="call  myinsert('$name','$city')";
$result=mysql_query($sql);
if($result)
{
echo "record inserted";

}
else

{

echo "record not inserted";

}

?>



======================================================================
DISPLAY  DATABASE RECORD USING MYSQL PROCEDURE IN PHP:
======================================================================
(1)FIRST CREATE  PROCEDURE mydisplay():

SQL>CREATE PROCEDURE mydisplay()

BEGIN

select * from tbl_ext;

End

(2)WRITE CODE FOR  display.php file:

<?php
$con=mysql_connect("Localhost","root","");
mysql_select_db('abhi',$con);
$sql="call mydisplay()";
$result=mysql_query($sql);
while($row=mysql_fetch_array($result))
{

echo $row['id'];
echo $row['name'];
echo $row['address'];
}
?>


======================================================================
UPDATE  DATABASE RECORD USING MYSQL PROCEDURE IN PHP:
======================================================================

(1)CREATE PROCEDURE  myupdate():

SQL>CREATE PROCEDURE myupdate(IN myid varchar(20),IN myname varchar(20),IN myaddress varchar(20))
BEGIN
update tbl_ext  set name=myname,address=myaddress where id=myid;
End

(2)NOW WRITE CODE FOR  update.html :

<form  action="update.php"  method="post">
id<input type=text name=id>
name<input type=text     name=name>
address<input type=text  name=address>
<input type=submit name=submit value="submit">
</form>

(3)NOW WRITE CODE FOR update.php  file:

<?php
$con=mysql_connect("Localhost","root","");
mysql_select_db('abhi',$con);
$id=$_POST['id'];
$name=$_POST['name'];
$city=$_POST['address'];
$sql="call myupdate('$id','$name','$city')";
$result=mysql_query($sql);
if($result)
{
echo "record updated";
}
else
{
echo "record not updated";
}
?>

======================================================================
DELETE   DATABASE RECORD USING MYSQL PROCEDURE IN PHP:
======================================================================
(1)FIRST CREATE PROCEDURE   mydelete():

CREATE PROCEDURE mydelete(IN myid varchar(20))
BEGIN
delete from tbl_ext  where id=myid;
End

(2)WRITE CODE FOR  delete.html  file:

<form  action="delete.php"  method="post">
id<input type=text name=id>
<input type=submit name=submit value="submit">
</form>

(3)NOW WRITE CODE FOR delete.php file:

<?php
$con=mysql_connect("Localhost","root","");
mysql_select_db('abhi',$con);
$id=$_POST['id'];

$sql="call mydelete('$id')";
$result=mysql_query($sql);
if($result)
{
echo "record deleted";
}
else
{
echo "record not deleted";
}
?>







Written by

We are Creative Blogger Theme Wavers which provides user friendly, effective and easy to use themes. Each support has free and providing HD support screen casting.

2 comments:

  1. Thanks for this amazing information. Good article about MySQL. Best PHP training in Bangalore

    ReplyDelete

  2. Really very informative and creative contents. This concept is a good way to enhance the knowledge.
    thanks for sharing. please keep it up.

    PHP MySQL Training in Gurgaon

    ReplyDelete

PHP Training Mumbai, PHP MySQL Training Mumbai, PHP Course Mumbai, PHP Institute Mumbai

 

© 2013 PHP TRAINING IN MUMBAI BY OM SIR . All rights resevered. Designed by OM SIR

Back To Top