简体   繁体   中英

php mysql data table save and edit on same page

i have data table, which has 5 rows and 5 rows has save and edit options separately. on submit it is submiting in the database and page is getting refreshed. but it should not refresh and on clicking update it should be updated in the same page. Help is appreciated.

Below is my code:

<?php
if(isset($_POST['save'])!="")
{
  $workname=mysql_real_escape_string($_POST['workname']);   
  $assignto=mysql_real_escape_string($_POST['name']);
  $phoneno=mysql_real_escape_string($_POST['phone_no']);
  $emailid=mysql_real_escape_string($_POST['emails']);
  $issuedate=mysql_real_escape_string($_POST['issue_date']);
  $deldate=mysql_real_escape_string($_POST['delivery_date']);
  $actualdeldate=mysql_real_escape_string($_POST['actual_delivery_date']);
  $remstrtfrm=mysql_real_escape_string($_POST['reminder_start']);
  $remtmeint=mysql_real_escape_string($_POST['reminder_time']);
  $remmsg=mysql_real_escape_string($_POST['reminder_message']);
  $wrkstat=mysql_real_escape_string($_POST['work_status']);
  $maker_id=mysql_real_escape_string($_SESSION['ADMIN_GAME_ID']);

 $create=mysql_query("INSERT INTO     dizypro_work_status_details(jobname,assign_to,phone_no,email_id,issue_date,delev    ry_date,actual_del_date,
    rem_strt_frm,reminder_time,reminder_message,work_status,maker_id,maker_date,row_    no)     VALUES('$workname','$assignto','$phoneno','$emailid','$issuedate','$deldate','$a    ctualdeldate','$remstrtfrm','$remtmeint','$remmsg','$wrkstat','$maker_id',now(),    '$row')");



 if($create)
  {
  $msg="Successfully Updated!!";
  echo "<script type='text/javascript'>alert('$msg');</script>";
  header('Location:add-work-detail.php');
  }
  else
  {
 $errormsg="Something went wrong, Try again";
  echo "<script type='text/javascript'>alert('$errormsg');</script>";
  }
  }

?>

<?php
if(isset($_POST['edit'])!="")
{
  $checkbox=mysql_real_escape_string($_POST['check']);  
  $assignto=mysql_real_escape_string($_POST['name']);
  $phoneno=mysql_real_escape_string($_POST['phone_no']);
  $emailid=mysql_real_escape_string($_POST['emails']);
  $issuedate=mysql_real_escape_string($_POST['issue_date']);
  $deldate=mysql_real_escape_string($_POST['delivery_date']);
  $actualdeldate=mysql_real_escape_string($_POST['actual_delivery_date']);
  $remstrtfrm=mysql_real_escape_string($_POST['reminder_start']);
  $remtmeint=mysql_real_escape_string($_POST['reminder_time']);
  $remmsg=mysql_real_escape_string($_POST['reminder_message']);
  $wrkstat=mysql_real_escape_string($_POST['work_status']);
  $maker_id=mysql_real_escape_string($_SESSION['ADMIN_GAME_ID']);

 $update=mysql_query("UPDATE     dizypro_work_status_details(check_box,jobname,assign_to,phone_no,email_id,issue_    date,delevry_date,actual_del_date,
    rem_strt_frm,reminder_time,reminder_message,work_status,maker_id,maker_date,row_    no)     VALUES('$checkbox','$work_name','$assignto','$phoneno','$emailid','$issuedate','        $deldate','$actualdeldate','$remstrtfrm','$remtmeint','$remmsg','$wrkstat','$mak    er_id',now(),'$row') WHERE maker_id='".$_SESSION['ADMIN_GAME_ID']."'");



 if($update)
  {
  $msg="Successfully Updated!!";
  echo "<script type='text/javascript'>alert('$msg');</script>";
  header('Location:add-work-detail.php');
  }
  else
  {
 $errormsg="Something went wrong, Try again";
  echo "<script type='text/javascript'>alert('$errormsg');</script>";
  }
  }

?>

Screenshot:

screenshot of form

use ajax, you can find a simple tutorial and what is ajax? from http://www.w3schools.com/ajax/ or for simplicity, use jQuery post() Method http://www.w3schools.com/jquery/ajax_post.asp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM