在同一页面中查询执行php脚本

问题描述:

I have this form html code in update.php. For updating, it's required to link to another page save_seeker.php with mysql update script for it to be executed. Is there any way to execute the script in same page on submitting form so that after query execution it remains on same page?

  <form action= "save_seeker.php" method = "post">
  Update details !<br><br>
  First Name
  <input type = "text" name = "fname" value = "<?php echo $disp['fname'];?>"><br><br> 
  Last Name 
  <input type = "text" name = "lname" value = "<?php echo $disp['lname'];?>"><br><br>
  Contact number
  <input type = "text" name = "contact" value = "<?php echo $disp['contact'];?>"><br><br>
  Email-id
  <input type = "email" name = "email" value = "<?php echo $disp['email'];?>"><br><br>
  Address
  <input type = "text" name = "address" value = "<?php echo $disp['address'];?>"><br><br> 
  Experience
  <input type = "number" name = "experience" value = "<?php echo $disp['experience'];?> "><br><br> 
  Qualification
  <input type = "text" name = "qualification" value = "<?php echo $disp['qualification'];?>"><br><br>
  <input type = "Submit" value = "Update">
  </form>   

You could do the processing in the same file by adding this into the form action.

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
    <!-- Input fields in here-->
    <input type="submit" name="form_submit" value="Submit">
</form>

Now check for the submit action by checking if it is set in the post variable

<?php 
    if ( isset( $_POST['form_submit'] ) ) {
        // Do processing here.
    }
?>

You could use the include('page-with-update.php') , call the update function and use the $_SERVER["PHP_SELF"].

I hope helped!!