Php 如何修复错误的sign_?
我的代码有错误。我的问题是不允许登录主页。数据库运行良好。验证很好。问题出在登录页面的脚本中。它仅在成功部分显示错误 这是我的档案: login1.phpPhp 如何修复错误的sign_?,php,forms,login,Php,Forms,Login,我的代码有错误。我的问题是不允许登录主页。数据库运行良好。验证很好。问题出在登录页面的脚本中。它仅在成功部分显示错误 这是我的档案: login1.php 登录屏幕 用户登录表单 登录 login1\u action.php <?php session_start(); include'connect.php'; if(isset($_POST['submit'])& !empty($_POST)){ //check the input is post or not
登录屏幕
用户登录表单
登录
login1\u action.php
<?php
session_start();
include'connect.php';
if(isset($_POST['submit'])& !empty($_POST)){ //check the input is post or not
$email=(strip_tags($_POST['userEmail'])); //post the input.
$password=md5(strip_tags($_POST['password']));
require"connect.php";
echo $q="select password,useremail from users where password='$password' and useremail='$email'"; //select the data from table for validation
$result=mysqli_query($con,$q);
$row=mysqli_fetch_assoc($result);
if($row['password']==$password){
echo "ok";
exit;
$_SESSION['user_session'] = $row['serialno'];
} else {
echo "email or password does not exist."; // wrong details
}
}
?>
login1.php中的:
- 在
上的样式值之外有一个分号。把它拉到双引号内
- 末尾有一个太多的
,并且
的嵌套顺序不正确
在login1_action.php中:
- 第一个条件语句在两个条件之间只有一个
&
。将此更改为&&
- 在声明$\u会话数据之前,您正在使用
exit
。在声明后移动退出
- 您的查询不安全。我建议你使用事先准备好的声明
- 您不是在查询中调用
serialno
列,而是在声明$\u会话['user\u SESSION']
值时从结果集中请求值
下面是使用准备好的语句的新代码块:
if($stmt=$con->prepare("SELECT `serialno` FROM `users` WHERE `useremail`=? AND `password`=?;")){
// stripping tags will do nothing to protect you
$email=$_POST['userEmail'];
$password=md5($_POST['password']);
$stmt->bind_param("ss",$email,$password);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($serialno);
if($stmt->fetch()){
$_SESSION['user_session']=$serialno;
echo "ok";
$stmt->free_result();
}else{
echo "Incorrect Username/Password Combination"; // Query Logic Error
}
$stmt->close();
}else{
echo "Query Syntax Error"; // echo mysqli_error($con);
}
我建议您替换md5()
函数。
阅读:你能告诉我错误吗?
$('document').ready(function() {
/* handling form validation */
$("#login-form").validate({
rules: {
password: {
required: true,
},
userEmail: {
required: true,
email: true
},
},
messages: {
password:{
required: "please enter your password"
},
userEmail: {required: "please enter your password"},
},
submitHandler: submitForm
});
/* Handling login functionality */
function submitForm() {
var data = $("#login-form").serialize();
$.ajax({
type : 'POST',
url : 'login1_action.php',
data : data,
beforeSend: function(){
$("#error").fadeOut();
$("#login_button").html('<span class="glyphicon glyphicon-transfer"></span> sending ...');
},
success : function(response){
if(response=="ok") {
$("#login_button").html('<img src="ajax-loader.gif" /> Signing In ...');
setTimeout(' window.location.href = "index1.php"; ',4000);
} else {
$("#error").fadeIn(1000, function() {
$("#error").html('<div class="alert alert-danger"> <span class="glyphicon glyphicon-info-sign"></span> '+response+' !</div>');
$("#login_button").html('<span class="glyphicon glyphicon-log-in"></span> Sign In');
});
}
}
});
return false;
}
});
if($stmt=$con->prepare("SELECT `serialno` FROM `users` WHERE `useremail`=? AND `password`=?;")){
// stripping tags will do nothing to protect you
$email=$_POST['userEmail'];
$password=md5($_POST['password']);
$stmt->bind_param("ss",$email,$password);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($serialno);
if($stmt->fetch()){
$_SESSION['user_session']=$serialno;
echo "ok";
$stmt->free_result();
}else{
echo "Incorrect Username/Password Combination"; // Query Logic Error
}
$stmt->close();
}else{
echo "Query Syntax Error"; // echo mysqli_error($con);
}