如何使用提交按钮保存数据库中的数据?

如何使用提交按钮保存数据库中的数据?

问题描述:

I am new to html & php and I appreciate your help. I am trying to accept user input into a webpage and then after the user clicks the submit button, write a new record out to MySQL. I am using Wordpress so the tags are not exactly textbook. So my first problem is that the submit button does not appear to execute the php code. I also would appreciate it if someone could check how I am passing my html field names to the php variables to make sure that I am on the right track. Thanks for your help!

     <form
      action="employee_list.php" method="post"
           <input type="submit"
         name="passport" id="passport" action="uraction" method="post" enctype="multipart/form-data"
    <label for="upload" >Select Employee Passport</label><input type="file" id="upload" name="upload" accept="image/*">
    <p/>
    <div class="form-group">
       <div class="form-row">
          <div class="col-md-6">
             <label for="name">Employee Full  Name</label>
             <input type="text" class="form-control" id="exampleInputName" aria-describedby="nameHelp" placeholder="Enter Full Name">
          </div>
          <div class="col-md-6">
             <label for="gender">Gender</label>
             <select type="text" class="form-control" id="exampleInputLastName" aria-describedby="nameHelp">
             </select>
          </div>
          <div class="col-md-6">
             <label for="maritalstatus">Marital Status</label>
             <select type="text" class="form-control" id="exampleInputLastName" aria-describedby="nameHelp">
             </select>
          </div>
          <div class="col-md-6">
             <label for="department">Department</label>
             <input type="text" class="form-control" id="Position" aria-describedby="nameHelp" placeholder="Enter The Department">
          </div>
          <div class="col-md-6">
             <label for="salary">Salary</label>
             <input type="number" class="form-control" id="salary" aria-describedby="nameHelp" placeholder="">
          </div>
          <div class="col-md-6">
             <label for="certificate"> Highest Certificate Acquired</label>
             <input type="text" class="form-control" id="salary" aria-describedby="nameHelp" placeholder="Enter  Highest Certificate Acquired">
          </div>
       </div>
    </div>
    <div class="form-group">
       <label for="Email">Email Address</label>
       <input type="emai" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
    </div>
    <div class="form-group">
       <label for="address">House Address</label>
       <input type="text" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter House Address">
    </div>
    <div class="form-group">
    <div class="form-row">
       <div class="col-md-6">
          <label for="phonenumber">Phone Number</label>
          <input type="number" class="form-control" id="phonenumber">
       </div>
       </form>
    </div>
    <!-- /.content-wrapper -->



    PHP script:
    <?php 
       if(isset($_POST['submit'])) { 
           $SQL = "INSERT INTO tbl_employee (name, gender, 
           marital_status,department,salary,certificate, email,address,phone_number) 
           VALUES ('$_POST[name]', '$_POST[gender]', 
           '$_POST[marital_status],'$_POST[department]','$_POST[salary]‌​
           ','$_POST[certificat‌​
           e]','$_POST[email]',‌​'$_POST[address]','$‌​_POST[phone_numer]')‌​"; $result = 
           mysql_query($SQL); 
       } 
       ?>   

 <html>
<head>
    <title>Check</title>
    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

    <!-- jQuery library -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

    <!-- Latest compiled JavaScript -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 

</head>
<body>
    <?php include('dbconnect.php');

    if($_POST['submit']){
        $fullname = $_POST['exampleInputName'];
        $gender = $_POST['gender'];
        $status = $_POST['status'];
        $position = $_POST['position'];
        $salary = $_POST['salary'];
        $certificate = $_POST['certificate'];
        $exampleInputEmail1 = $_POST['exampleInputEmail1'];
        $phonenumber = $_POST['phonenumber'];            
    }        

    $data = "INSERT INTO test (`id`, `fullname`, `gender`, `matrial_status`, `department`, `salary`, `certificate`, `email`, `address`)VALUES ('', '$fullname', '$gender', '$status', '$position', '$salary', '$certificate', '$exampleInputEmail1', '$phonenumber')";        

    mysqli_query($con,$data);

    ?>
    <form action="checkbox.php" method="POST" >
        <div class="form-group">
            <div class="form-row">
                <div class="col-md-6">
                    <label for="name">Employee Full  Name</label>
                    <input type="text" class="form-control" id="exampleInputName" name="exampleInputName" aria-describedby="nameHelp" placeholder="Enter Full Name">
                </div>
                <div class="col-md-6">
                    <label for="gender">Gender</label>
                    <select type="text" name="gender" class="form-control" id="gender" aria-describedby="nameHelp">
                        <option value="Male">Male</option>
                        <option value="Female">Female</option>
                    </select>
                </div>

                <div class="col-md-6">
                    <label for="maritalstatus">Marital Status</label>
                    <select type="text" name="status" class="form-control" id="status" aria-describedby="nameHelp">
                        <option value="Married">Married</option>
                        <option value="Unmarried">Unmarried</option>
                    </select>
                </div>
                <div class="col-md-6">
                    <label for="department">Department</label>
                    <input type="text" class="form-control" name="position" id="position" aria-describedby="nameHelp" placeholder="Enter The Department">
                </div>
                <div class="col-md-6">
                    <label for="salary">Salary</label>
                    <input type="number" class="form-control" name="salary" id="salary" aria-describedby="nameHelp" placeholder="">
                </div>
                <div class="col-md-6">
                    <label for="certificate"> Highest Certificate Acquired</label>
                    <input type="text" class="form-control" id="certificate" name="certificate" aria-describedby="nameHelp" placeholder="Enter  Highest Certificate Acquired">
                </div>
            </div>
        </div>
        <div class="form-group">
            <label for="Email">Email Address</label>
            <input type="emai" class="form-control" id="exampleInputEmail1" name="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
        </div>
        <div class="form-group">
            <label for="address">House Address</label>
            <input type="text" class="form-control" id="exampleInputEmail1" name="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter House Address">
        </div>
        <div class="form-group">
            <div class="form-row">
                <div class="col-md-6">
                    <label for="phonenumber">Phone Number</label>
                    <input type="text" class="form-control" name="phonenumber" id="phonenumber">
                </div>
            </div>
        </div>

        <input type="submit" name="submit" id="passport">
    </form>
</body>