我嘗試註冊,頁面給出的數據未輸入消息。我以前用幾乎相同的語法創建了許多頁面,但只有給定的語法不起作用。如果密碼驗證循環進入兩個循環,但在最後一個循環中跳轉到其他位置,我試圖通過查詢輸入數據。幫我糾正我的錯誤。謝謝PHP註冊表格無法正常工作
<?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>
這會給你BTW假陽性'如果(isset($ _ POST [ '提交'])== 1)'使用隱藏輸入' '並且很可能永遠不會開火。 –
你的錯誤?讓我們看看..真正的逃脫密碼?將密碼保存爲純文本?打開sql注入(真正的轉義字符串不能完全保護你)?我不確定這是什麼,但如果你繼續沿着這條道路前進,你會遇到很多問題。 – icecub
請查閱以下鏈接http://php.net/manual/en/mysqli.error.php和http://php.net/manual/en/function.error-reporting.php 並將其應用於您的代碼。 –