
PK 
<?php
include_once('../include/connection.php');
/*echo '<pre>';
print_r($_POST);
echo '<pre>';*/
$imgName = $_FILES['img']['name'];
$tmpName = $_FILES['img']['tmp_name'];
$sqlSelectForImg="SELECT * FROM certificate order by cId desc";
$sqlQueryForImg=mysql_query($sqlSelectForImg);
$sqlFetchForImg=mysql_fetch_array($sqlQueryForImg);
if($_POST['action']=="edit") {
$sqlSelectForImgEdit="SELECT * FROM certificate WHERE cId=".$_POST['cId'];
$sqlQueryForImgEdit=mysql_query($sqlSelectForImgEdit);
$sqlFetchForImgEdit=mysql_fetch_array($sqlQueryForImgEdit);
//echo $sqlFetchForImgDel['imgName'];
if(!empty($imgName)){
$unlink = "student_images/".$sqlFetchForImgEdit['img'];
@unlink($unlink);
$imageNew = $_POST['cId'].$sqlFetchForImg['cId'].$imgName;
}else{
$imageNew = $sqlFetchForImgEdit['img'];
}
} else {
$imageNew = $sqlFetchForImg['cId'].$imgName;
}
@mkdir ("student_images");
@move_uploaded_file($tmpName,"student_images/".$imageNew);
$certificateNo = $_POST['certificateNo'];
$name = $_POST['name'];
$fatherName = $_POST['fatherName'];
$regNo = $_POST['regNo'];
$admiDate = $_POST['admiDate'].$_POST['year']."-".$_POST['mon']."-".$_POST['day'];
$course = $_POST['course'];
$grade = $_POST['grade'];
$duration = $_POST['duration'];
$address = $_POST['address'];
$centerName = $_POST['centerName'];
if($_POST['action']=='add') {
$insertForCertificate="INSERT INTO certificate (certificateNo,name,fatherName,regNo,admiDate,course,grade,
duration,address,centerName,img)
VALUES ('".$certificateNo."','".$name."','".$fatherName."','".$regNo."',
'".$admiDate."','".$course."','".$grade."','".$duration."','".$address."',
'".$centerName."','".$imageNew."')";
$queryForCertificate=mysql_query($insertForCertificate);
header('location: form_list.php');
}
if($_POST['action']=='edit') {
$updateForFeedBack="UPDATE certificate SET
certificateNo='".$certificateNo."',
name='".$name."',
fatherName='".$fatherName."',
regNo='".$regNo."',
admiDate='".$admiDate."',
course='".$course."',
grade='".$grade."',
duration='".$duration."',
address='".$address."',
centerName='".$centerName."',
img='".$imageNew."'
WHERE cId='".$_POST['cId']."'";
$queryForFeedBack=mysql_query($updateForFeedBack);
header('location: form_list.php');
}
if($_GET['action']=='delete')
{
$del="DELETE FROM certificate where cId='".$_GET['cId']."'";
$result=mysql_query($del);
header('location: form_list.php');
}
?>


PK 99