我想使用php保存数据库表中的输入选择选项

时间:2017-05-21 21:12:27

标签: php html mysql database

我想使用php在数据库表中保存输入选择选项。我想将它保存在具有现有属性的表中 我知道如何在使用单独的表时添加它,但我想在现有的表中添加它,只有很少的其他属性

ps第一个问题是熊我

<?php 

if(isset($_POST['signup'])) {

    $name = $_POST['name'];
    $email = $_POST['email'];
    $phone = $_POST['phone'];
    $password = $_POST['password'];
    $department = $_POST['deptlist'];

    echo $name;

    $connection = mysqli_connect('localhost', 'root', '', 'filetracking');    

    if($connection) {
        echo "We are connected";
    } else {
        die("Database connection failed");
    }

    $query = "INSERT INTO faculty(name,email,contactno,password,office) ";
    $query .= "VALUES ('$name', '$email', '$phone', '$password', '$department')";

    $result = mysqli_query($connection, $query);
    if(!$result) {
        die('Query FAILED' . mysqli_error($connection));
    } else {
        echo "Record Create"; 
    }
}

?>

<form method="post" action="signup.php">
    <div class="form-group">
        <label for="name" class="control-label">Name</label>
        <input type="text" name="name" id="Name" class="inputmd textinput form-control required" placeholder="Full Name" style="margin-bottom: 10px" required="true">
    </div>

    <div class="form-group">
        <label for="email" class="control-label">Email</label>
        <input type="email" name="email" id="Email" class="inputmd textinput form-control required" placeholder="Email" style="margin-bottom: 10px" required="true">
    </div>

    <div class="form-group">
        <label for="phone" class="control-label">Phone</label>
        <input type="number" name="phone" id="Phone" class="inputmd textinput form-control required" placeholder="Phone No" style="margin-bottom: 10px" required="true">
    </div>

    <div class="form-group">
        <label for="password" class="control-label">Password</label>
        <input type="password" name="password" id="Password" class="inputmd textinput form-control" placeholder="Password" style="margin-bottom: 10px" required="true">
    </div>

    <div class="form-group">                        
        <label for="deptlist" class="control-label">Department</label>
        <select name="deptlist" form="deptform" class="inputmd form-control" style="margin-bottom: 10px">
            <option value="DCSE">Department of Computer Systems Engineering</option>
            <option value="DME">Department of Mechanical Engineering</option>
            <option value="DEE">Department of Electrical Engineering</option>
            <option value="DCS">Department of Computer Science</option>
        </select>

    <div class="form-group">                    
        <input type="submit" name="signup" id="Singup" value="Sign Up" class="btn btn-info col-md-4 col-md-offset-4">
    </div>

</div>

1 个答案:

答案 0 :(得分:0)

您错误地提到了名为deptform <select name="deptlist" form="deptform"的表单,但没有这样的表单。这可以防止脚本接收此数据。