我正在尝试将表单中的数据插入mySQL DB,没有连接错误,但没有数据插入到我的数据库中。任何的想法? 这是我的HTML表单:
<div class="tab-pane" id="Registration">
<b><em>Listen to the voice of Soul</em></b>
<form class="form" role="form" method="POST" action="signup.php" accept-charset="UTF-8"id="signup-nav">
<div class="form-group">
<label class="sr-only" for="email2">Email address</label>
<input type="email" class="form-control"id="email2" name="signup_email" placeholder="Email address" required>
</div>
<div class="form-group">
<label class="sr-only" for="password2">Password</label>
<input type="password" class="form-control" id="pwd2" name="signup_pwd" placeholder="Password" required>
</div>
<div class="form-group">
<label class="sr-only" for="password3">Confirm Password</label>
<input type="password" class="form-control" id="pwdcon" name="signup_pwdcon" placeholder="Confirm Password" required>
</div>
<div class="form-group">
<input type="submit" name="signUpBtn" value="Sign Up" class="btn btn-primary btn-block"></button>
</div>
</form>
</div>
我的数据库名称是coldplay,table是userdata,我是使用ID = root的本地主机,没有密码
PHP:
<?php
include ("dbh.php");
if(isset($_POST["signUpBtn"])){
$signup_email = $_POST ['signup_email'];
$signup_pwd = $_POST ['signup_pwd'];
$signup_pwdcon = $_POST ['signup_pwdcon'];
$sql_signup = "insert into userdata (email, pwd, pwdcon)
values ('$signup_email', '$signup_pwd', '$signup_pwdcon')";
mysqli_query($conn, $sql_signup);
mysqli_close($conn);
header("Location: testing.html");
}
?>
PHP数据库处理程序:
<? php
$conn = mysqli_connect("localhost", "root", "", "coldplay");
if (!$conn){
die("Connection failed: ".mysqli_connect_error());
}
?>
答案 0 :(得分:0)
请先阅读password hashing和how to bind parameters to prepared statements in mysqli。如果你这样做,你的脚本很容易被sql注入。
你的dbh.php文件中存在一个问题,其中包含打开的php标记。它应该读<?php
<? php
mysqli_query
的内容(注意空格)。
如果这不是问题,您应该检查if (!mysqli_query($conn, $sql_signup)) {
echo "Error: " . mysqli_error($conn);
}
方法的结果,如下所示:
<html>
<body>
<p>
<select ng-model="selectedValue" ng-option="c1.name in c1 in c in personInfo.city"></select>
</p>
</body>
>/html>