dqxafj6830 2017-09-11 13:13
浏览 162
已采纳

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

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); 
       } 
       ?>   
  • 写回答

1条回答 默认 最新

  • dongzheng8463 2017-09-11 14:23
    关注
     <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>
    

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示