不推荐使用:函数mysql()已弃用 第39行/home/u624273934/public_html/ecommerce/admin_area/login.php
警告:mysql()期望参数1是字符串,对象是给定的 第39行/home/u624273934/public_html/ecommerce/admin_area/login.php
警告:mysql_result()需要至少2个参数,1中给出1 第41行/home/u624273934/public_html/ecommerce/admin_area/login.php
代码是这样的:
<?php
session_start();
?>
<!DOCTYPE>
<html>
<head>
<title>Login Form</title>
<link rel="stylesheet" href="styles/login_style.css" media="all" />
</head>
<body>
<div class="login">
<h2 style="color:white; text-align:center;"><?php echo @$_GET['not_admin']; ?></h2>
<h2 style="color:white; text-align:center;"><?php echo @$_GET['logged_out']; ?></h2>
<h1>Admin Login</h1>
<form method="post" action="login.php">
<input type="text" name="user_email" placeholder="Email" required="required" />
<input type="password" name="user_pass" placeholder="Password" required="required" />
<button type="submit" class="btn btn-primary btn-block btn-large" name="login">Login</button>
</form>
</div>
</body>
</html>
<?php
if(isset($_POST['login'])){
$user_email = $_POST['user_email'];
$user_pass = $_POST['user_pass'];
$sel_c = "select * from admins where user_pass='$user_pass' AND user_email='$user_email'";
$run_c = mysql($con, $sel_c);
$check_customer = mysql_result($run_c);
if($check_customer==0){
echo "<script>alert('Password or email is incorrect, plz try again!')</script>";
exit();
}
$ip = getIp();
$sel_cart = "select * from cart where ip_add='$ip'";
$run_cart = mysqli_query($con, $sel_cart);
$check_cart = mysqli_num_rows($run_cart);
if($check_customer>0 AND $check_cart==0){
$_SESSION['user_email']=$user_email;
echo "<script>alert('You logged in successfully, Thanks!')</script>";
echo "<script>window.open('customer/my_account.php','_self')</script>";
}
else {
$_SESSION['user_email']=$user_email;
echo "<script>alert('You logged in successfully, Thanks!')</script>";
echo "<script>window.open('checkout.php','_self')</script>";
}
}
?>
答案 0 :(得分:0)
您正在使用弃用的方法。不鼓励使用mySql_
方法支持mysqli_
方法。 (注意i
)
<强>替换强>
$run_c = mysql($con, $sel_c);
$check_customer = mysql_result($run_c);
。通过强>
$run_cart = mysqli_query($con, $sel_c);
$rows = array();
while ($row = mysqli_fetch_assoc($run_cart)) {
$rows[] = $row;
}
您之后在脚本中使用了mysqli
$run_cart = mysqli_query($con, $sel_cart);
$check_cart = mysqli_num_rows($run_cart);