Add Edit Delete using mysql and php Language.

 

Add Record

$name = $_POST['studentname'];
$class = $_POST['class'];
$address = $_POST['address'];
$sql = "insert into tbl_student(name, class,address) values('$name','$class','$address')";
if(mysql_query($sql) or die(mysql_error()))
{
  header('Location: index.php?m=1');
//echo "success";
}
else
{
   header('Location: index.php?m=0');
//echo "fail";
}

 


Edit Record

$id = $_POST['id'];
$name = $_POST['studentname'];
$class = $_POST['class'];
$address = $_POST['address'];
$sqli = mysql_query("update tbl_student set
name = '$name',
class = '$class',
address = '$address' where id = '$id'") or die(mysql_error());
if(mysql_affected_rows() >0)
{
header('Location: index.php?m=4&id='.$id);
//echo "success";
}
else
{
header('Location: index.php?m=5&id='.$id);
//echo "fail";
}


Delete Record

$id =isset($_GET['id'])? $_GET['id'] : "";


$sql = mysql_query("START TRANSACTION");
$del = "delete from tbl_student where id = '$id'";
if(mysql_query($del) or die(mysql_error()))
{
mysql_query("COMMIT");
header('Location: index.php?&m=6');
}
else
{
mysql_query("ROLLBACK");
header('Location: index.php?&m=7');
}

Download demo

If love this tutorial Please Like this page