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

问题描述 投票:0回答:2

php表单没有提交或从表单到我的数据库执行任何操作,尽管遵循将表单连接到mysql与php的所有规则

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>";
}

请告诉我似乎是我遗失或未看到的问题

php html5
2个回答
1
投票

尝试首先连接db并将链接传递给您的查询

    $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注入和其他东西。


0
投票

首先,谢谢大家的支持,我只是错过了表单所连接到用于提交数据的JS文件的ID,这就是为什么表单没有看到PHP代码

一旦删除一切都工作正常

谢谢你们

© www.soinside.com 2019 - 2024. All rights reserved.