为什么不赢得我的数据库更新?

时间:2017-05-16 11:25:30

标签: php html mysql sql forms

我在将表单发送到数据库时遇到问题。我目前正在学习初级课程,但是运行它的人遗漏了一些内容并且似乎没有回答问题。我的网站连接到数据库很好,我可以调用内容到网站。我也尝试在设置提交按钮后回显页面输入到页面,这样可行,所以我认为它与我的SQL有关吗?插入和数据库头的所有标题都完全相同。任何帮助,将不胜感激!代码如下:

<!DOCTYPE html>
<html>
<head>

    <title>New Form</title>
    <script src="js/jquery.js"></script>
    <script src="bootstrap/js/bootstrap.js"></script>
    <link rel="stylesheet" href="bootstrap/css/bootstrap.css">
    <style>
    .my-fixed   { resize: none;
        }
    </style>
</head>
<body>
    <div class="container">
    <h1>Submit Form</h1>
        <form class="form-horizontal" action="form_process.php" method="POST" role="form">
            <div class="form-group">
                <label for="name" class="control-label col-sm-2">Name *</label>
                <div class="col-sm-5">
                    <input type="text" id="name" name="name" class="form-control" placeholder="Full Name" required />
                </div>
            </div>
            <div class="form-group">
                <label for="email" class="control-label col-sm-2">Email *</label>
                <div class="col-sm-5">
                    <input type="email" id="email" name="email" class="form-control" placeholder="Email Address" required />
                </div>
            </div>
            <div class="form-group">
                <label for="subject" class="control-label col-sm-2">Subject *</label>
                <div class="col-sm-5">
                    <input type="text" id="subject" name="subject" class="form-control" placeholder="Add a Subject" required />
                </div>
            </div>
            <div class="form-group">
                <label for="gender" class="control-label col-sm-2">Gender</label>
                <div class="col-sm-2">
                    <select class="form-control" name="gender">
                        <option  value="">Select gender</option>
                        <option value="male">Male</option>
                        <option value="female">Female</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
            <label class="control-label col-sm-2">Skills</label>
            <div class="col-sm-5">
            <label class="checkbox-inline" for="skill1"><input type="checkbox" name="skill1">HTML</label>
            <label class="checkbox-inline" for="skill2"><input type="checkbox" name="skill2">PHP</label>
            <label class="checkbox-inline" for="skill3"><input type="checkbox" name="skill3">CSS</label>
            <label class="checkbox-inline" for="skill4"><input type="checkbox" name="skill4">JavaScript</label>
                </div>
            </div>
            <div class="form-group">
                <label for="country" class="control-label col-sm-2">Country</label>
                <div class="col-sm-2">
                    <select class="form-control" name="country">
                        <option  value="">Select country</option>
                        <option value="ireland">Ireland</option>
                        <option value="uk">UK</option>
                        <option value="france">France</option>
                        <option value="usa">USA</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label for="comments" class="control-label col-sm-2">Comments *</label>
                <div class="col-sm-5">
                    <textarea class="form-control my-fixed" name="comments" id="comments" rows="8" required></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-sm-2"></label>
                <div class="col-sm-5">
                <input type="submit" class="btn btn-default btn-block" name="submit_form" value="Submit form">
                </div>
            </div>
        </form>
    </div>
</body>
</html>

这就是它的所在:

<?php
session_start();
include 'includes/db.php';

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

    $name = strip_tags($_POST['name']);
    $email = strip_tags($_POST['email']);
    $subject = htmlspecialchars($_POST['subject']);
    $gender = $_POST['gender'];
    $country = $_POST['country'];
    $comments = trim(htmlspecialchars($_POST['comments']));

    if(empty($_POST['skill1'])){
        $_POST['skill1'] = '';

    }
    if(empty($_POST['skill2'])){
        $_POST['skill2'] = '';

    }
    if(empty($_POST['skill3'])){
        $_POST['skill3'] = '';

    }
    if(empty($_POST['skill4'])){
        $_POST['skill4'] = '';

    }

    $ins_sql = "INSERT INTO comments (name, email_address, subject, gender, skill1, skill2, skill3, skill4, country, comments) VALUES ('$name', '$email', '$subject', '$gender', '$_POST[skill1]', '$_POST[skill2]', '$_POST[skill3]', '$_POST[skill4]', $country, $comments )";
    $run_sql = mysqli_query($conn, $ins_sql);

    echo 'Thank You!';
    echo $name, $email, $subject, $gender, $_POST['skill1'], $_POST['skill2'], $_POST['skill3'], $_POST['skill4'], $country, $comments;
} else  {

}

?>

0 个答案:

没有答案