html5表单不使用php不提交也不对mysql表采取行动

时间:2019-03-25 20:04:52

标签: php html5

php表单尽管遵循了使用php将表单连接到mysql的所有规则,但并未提交表单或对表单进行任何操作

应该使用名称标签从表单中获取信息的php代码,但是提交数据时不会执行任何操作,也不会发生任何错误

HTML表单

<form id="contactForm" method="post" action="register.php">
    <div class="row">
        <div class="col-md-6 wow fadeInLeft">
            <div class="input-group">
                <label class="sr-only" for="name">Name</label>
                <span class="input-group-addon" id="basic-addon1"><i class="fa fa-user"></i></span>
                <input id="name" name="name" type="text" class="form-control"  required="" placeholder="Name">
            </div>
        </div>
        <div class="col-md-6 wow fadeInRight">
            <div class="input-group">
                <label class="sr-only" for="email">Email address</label>
                <span class="input-group-addon" id="basic-addon2"><i class="fa fa-envelope"></i></span>
                <input id="email" name="email" type="email" class="form-control" required="" placeholder="Email">
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-md-6 wow fadeInLeft">
            <div class="input-group">
                <label class="sr-only" for="phone">Phone</label>
                <span class="input-group-addon" id="basic-addon3"><i class="fa fa-phone"></i></span>
                <input id="phone" name="mobile" type="tel" class="form-control" placeholder="Phone">
            </div>
        </div>
        <div class="col-md-6 wow fadeInRight">
            <div class="input-group">
                <label class="sr-only" for="subject">Location</label>
                <span class="input-group-addon" id="basic-addon4"><i class="fa fa-file-text"></i></span>
                <input id="subject" name="location" type="text" class="form-control" required="" placeholder="location">
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-md-6 wow fadeInLeft">
            <div class="input-group">
                <label class="sr-only" for="phone">Username</label>
                <span class="input-group-addon" id="basic-addon3"><i class="fa fa-phone"></i></span>
                <input id="phone" name="username" type="text" class="form-control" required=""placeholder="username">
            </div>
        </div>
        <div class="col-md-6 wow fadeInRight">
            <div class="input-group">
                <label class="sr-only" for="subject">Password</label>
                <span class="input-group-addon" id="basic-addon4"><i class="fa fa-file-text"></i></span>
                <input id="subject" name="password" type="text" class="form-control" required="" placeholder="password">
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-md-12 wow fadeInRight">
            <div class="input-group">
                 <label class="sr-only" for="subject">Interest</label>
                 <span class="input-group-addon" id="basic-addon4"><i class="fa fa-file-text"></i></span>
                 <input id="subject" name="interest" type="text" class="form-control" required="" placeholder="interest">
             </div>
         </div>
     </div>
     <input type="submit" class="btn btn-primary btn-lg btn-block" name="submit" value="Register">
</form>

PHP表单

if (isset($_POST['submit'])) {
$name = $_POST['name'];
$mobile = $_POST['mobile'];
$email = $_POST['email'];
$cusername = $_POST['username'];
$cpassword = $_POST['password'];
$location = $_POST['location'];
$interest = $_POST['interest'];

 $sql = "INSERT INTO users(name,email,mobile,location,username,password,interest) 
    VALUES('$name','$email','$mobile','$location','$cusername','$cpassword','$interest')";
    mysql_query($sql) or die(mysql_error());
    session_start();
    $_SESSION['username']=$cusername;
echo "<script type=\"text/javascript\">
alert(\"Registration Complete , you will be redirected shortly\");
window.location = \"profile.php\"
</script>";
}

请告知我似乎缺少或看不到的问题

2 个答案:

答案 0 :(得分:1)

首先尝试与数据库连接,然后将链接传递到您的查询中

    $link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
    if (!$link) {
        die('Could not connect: ' . mysql_error());
    }

    $sql = "INSERT INTO users(name,email,mobile,location,username,password,interest) VALUES('$name','$email','$mobile','$location','$cusername','$cpassword','$interest')";
    // here put your LINK-CONNECTION
    mysql_query($sql,$link) or die(mysql_error());


    mysql_close($link);

,请过滤您从帖子中的字段中获得的内容,以避免sql注入和其他内容。

答案 1 :(得分:0)

首先感谢大家的支持,我只是错过了表单具有的ID,该ID已连接到JS文件以提交数据,这就是为什么表单没有看到php代码的原因

删除所有内容后一切正常

谢谢大家