Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用提交按钮在数据库中保存数据?_Php_Mysql - Fatal编程技术网

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

Php 如何使用提交按钮在数据库中保存数据?,php,mysql,Php,Mysql,我是html和php新手,非常感谢您的帮助。我试图接受用户对网页的输入,然后在用户单击submit按钮后,将新记录写入MySQL。我用的是Wordpress,所以标签不完全是教科书上的。 因此,我的第一个问题是提交按钮似乎没有执行php代码。如果有人能检查我是如何将html字段名传递给php变量的,以确保我走上了正确的轨道,我也将不胜感激。谢谢你的帮助 <form action="employee_list.php" method="post"

我是html和php新手,非常感谢您的帮助。我试图接受用户对网页的输入,然后在用户单击submit按钮后,将新记录写入MySQL。我用的是Wordpress,所以标签不完全是教科书上的。 因此,我的第一个问题是提交按钮似乎没有执行php代码。如果有人能检查我是如何将html字段名传递给php变量的,以确保我走上了正确的轨道,我也将不胜感激。谢谢你的帮助

     <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); 
       } 
       ?>   

您的表单看起来未完成且格式不正确,请不要在评论中发布代码,请改为编辑您的帖子。每次在新代码中使用数据库扩展时,它都会被弃用,多年来一直在PHP7中消失。如果您只是在学习PHP,请将精力花在学习PDO或mysqli数据库扩展和准备好的语句上。您的脚本甚至有可能使用没有方法或操作的输入;重新检查您的表单语法。您必须在该代码的帮助下更改代码,它将在@KanuUgochukwu.运行。!这是经过测试的代码。
 <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>