我尝试注册并且页面给出未输入数据的消息。我以前用几乎相同的语法制作了很多页面,但只有给定的一个不起作用。在密码验证的循环中进入两个,但在最后的循环中跳转到其他我试图通过查询输入数据。帮我纠正我的错误。谢谢
<?php
#start session
session_start();
#Database connection here
$dbc = mysqli_connect('localhost','root','farmstockexchange','fse') OR die('ERROR :'.mysqli_connect_error());
if (isset($_POST['submitted'])==1)
{
$username = mysqli_real_escape_string($dbc, $_POST['username']);
$email = mysqli_real_escape_string($dbc, $_POST['email']);
$password = mysqli_real_escape_string($dbc, $_POST['password']);
$passwordv = mysqli_real_escape_string($dbc, $_POST['passwordv']);
if ($username && $password && $passwordv) {
if ($password == $passwordv)
{
$q = "INSERT INTO user (username, email, password) VALUES ('$username', '$email', SHA1('$password')";
$r = mysqli_query($dbc, $q);
if ($r)
{
header('location:reg1.php');
}
else
{
echo 'data not entered';
}
}//$password == $passwordv
else {
echo 'password didnt match';
}
} // $username && $password && $passwordv
else
{
echo 'please enter some data or error :'.mysqli_error($dbc);
echo '<p>'.$q.'</p>';
}
<!-- there some problem in this loop -->
}
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<?php include('../config/css.php'); ?> <!-- bootstrap cdn -->
<?php include('../config/js.php'); ?> <!-- bootstrap cdn -->
</head>
<body>
<div id="wrap">
<div class="container">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<div class="panel panel-info">
<div class="panel-heading"><strong>Register</strong></div><!-- panel heading-->
<div class="panel-body">
<form action="register.php" method="post"><!-- basic registration form-->
<div class="form-group">
<label for="username">Username</label>
<input type="text" class="form-control" id="username" name="username" placeholder="User name" required>
</div>
<div class="form-group">
<label for="email">Email address</label>
<input type="email" class="form-control" id="email" name="email" placeholder="Email Address" required>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" id="password" name="password" placeholder="Password" required>
</div>
<div class="form-group">
<label for="passwordv">Password</label>
<input type="password" class="form-control" id="passwordv" name="passwordv" placeholder="Password Verification" required
>
</div>
<button type="submit" class="btn btn-primary btn-lg btn-block">Register</button>
<input type="hidden" name="submitted" value="1">
</form>
</div> <!-- panel body -->
</div><!-- panel end -->
</div><!-- column end -->
</div><!-- row end -->
</div><!-- container end -->
</div> <!-- wrap end -->
</body>
</html>
答案 0 :(得分:0)
您没有结束SQL变量。 将其更改为
$q = "INSERT INTO user (username, email, password) VALUES ('$username', '$email', SHA1('$password'))";
你有一个)