Warning: mysqli_query() expects at least 2 parameters, 1 given in /home/tdoylex1/public_html/dorkhub/index.php on line 4
大概意思是mysqli_query()至少需要2个参数,其中1个给定。
原本的代码是
<?php $name = $_POST['name']; $password = $_POST['password']; try{ $pdo = new PDO("mysql:host=localhost;dbname=php;","root","123456"); }catch(PDOException $e){ die("数据库连接失败".$e->getMessage()); } $sql = "SELECT * FROM login WHERE username ='{$name}' and password='{$password}'";
$rst=mysqli_query( $sql); $row=mysqli_fetch_assoc($rst); if($row){ echo "<script> alert('登录成功!'); window.location='main2.php'; //跳转 </script>"; } else { echo "<script> alert('用户不存在或密码错误!'); window.history.back(); //返回上一页 </script>"; } ?>
修改为
<?php $name = $_POST['name']; $password = $_POST['password']; // .连接数据库 // .防止中文乱码 $con=mysqli_connect("localhost","root","123456","php"); // .拼接sql语句,取出信息 $sql = "SELECT * FROM login WHERE username ='{$name}' and password='{$password}'"; $rst=mysqli_query( $con,$sql); $row=mysqli_fetch_assoc($rst); if($row){ echo "<script> alert('登录成功!'); window.location='main2.php'; //跳转 </script>"; } else { echo "<script> alert('用户不存在或密码错误!'); window.history.back(); //返回上一页 </script>"; } ?>
还有mysqli与mysql是看你的php版本,版本不一样代码也有一定的差别