我提交表单时找不到页面,但是当我重新加载相同的网址时显示该页面

我提交表单时找不到页面,但是当我重新加载相同的网址时显示该页面

问题描述:

I am using the following template file to create a new page from wordpress dashboard.

<?php 
  /*
    Template Name: admin info form
  */
?>

<?php 
require_once('includes/Admin_profile.php');
require_once('includes/session.php');

get_header(); 

?>



  <?php 
if(isset($_POST['submit-btn']))
{


   $admin_info=new Admin_profile();
   $admin_info->admin_prof_id=$_SESSION['admin_id'];
   $admin_info->name=$_POST['name'];
   $admin_info->degree=$_POST['degree'];
   $admin_info->school=$_POST['school'];
   $admin_info->college=$_POST['college'];
   $admin_info->uni=$_POST['uni'];
   $admin_info->pres_addr=$_POST['pres_addr'];
   $admin_info->per_addr=$_POST['per_addr'];
   $admin_info->mobile=$_POST['mobile'];
   $admin_info->department=$_POST['dept'];
    $admin_info->save(); 




}


?>
 <div id="admin-login-form"> 
<div class="error_required_fields">Fill up all required fields. * indicated fields are required</div>

  <form name="input" action="#" method="post">
    <table>

      <tr><td> Name:</td><td><input class="name" type="text" name="name" /></td> <td><p class="required">*</p></div></td></tr>
      <tr><td> Last academic degree:</td><td><input class="degree" type="text" name="degree" /></td> <td><p class="required">*</p></td></tr>
      <tr><td> School:</td><td><input class="school" type="text" name="school" /></td><td><p class="required">*</p></td></tr> 
       <tr><td> College:</td><td><input class="college" type="text" name="college" /></td> </tr>
       <tr><td> University:</td><td><input class="uni" type="text" name="uni" /></td> </tr>
       <tr><td>Present Address:</td><td><input class="pres_addr" type="textarea" name="pres_addr" /></td><td><p class="required">*</p></td></tr> 
       <tr><td>Present Address:</td><td><input class="per_addr" type="textarea" name="permanent_addr" /></td> <td><p class="required">*</p></td></tr>
       <tr><td>Mobile number:</td><td><input class="mobile" type="text" name="mobile" /></td> <td><p class="required">*</p></td></tr>  

       <tr><td>Mobile number:</td><td><input class="mobile" type="text" name="mobile" /></td> <td><p class="required">*</p></td></tr> 
       <tr><td>Depertment:</td><td>
       <select name="options">
      <option value="not selected" selected="selected">Choose favorite subject</option>
                <option value="Mathematics">Mathematics</option>
                <option value="Chemestry">Chemestry</option>
                <option value="Biology">Biology</option>

       </select></td>
       <td><p class="required">*</p></td>
       </tr>


      <tr><td> </td><td class="btn"> <input type="submit" class="submit-btn" name="submit-btn" value="Submit" /></td></tr>
    </table> 

</form>

      </div>       


   <?php

    get_footer();
    ?>

But when I submit the form it shows- 404 error (No page found). I notice that url is: http://localhost/wordpress/admin-info/# . I copy this url and paste it in a new tab. Then it show the page. What problem going on. please help.

I got solution. Here I used "name" for a name filed of a form. just avoid naming your input fields "name" to avoid this error.

Are you trying to have the page submit to itself? Could you change the action to:

($_SERVER['PHP_SELF'])