PHP bug:Warning: mysqli_connect(): (HY000/1045): Access denied for user ‘root‘@‘localhost‘ (using pa

Warning: mysqli_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: YES) in C:\xampp\htdocs\stiterm\student_insert.php on line 24
���ݿ����������ʧ�ܣ�

code show as below:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>新闻列表</title>
<style>
body {
    
     margin:0; padding:0; font:70% Arial, Helvetica, sans-serif; color:#555; line-height:150%; text-align:left; }
a {
    
     text-decoration:none; color:#057fac; }
h1 {
    
     font-size:140%; margin:0 20px; line-height:80px; }
#container { margin:0 auto; width:680px; background:#fff; padding-bottom:20px; }
#content { margin:0 20px; }
form {
    
     margin:1em 0; padding:.2em 20px; }
table, td{
    
    
	font:100% Arial, Helvetica, sans-serif; 
}
table{
    
    width:100%;border-collapse:collapse;margin:1em 0;}
th, td{
    
    text-align:left;padding:.5em;border:1px solid #fff;}
th{
    
    background:#328aa4 url(tr_back.gif) repeat-x;color:#fff;}
td{
    
    background:#e5f1f4;}
</style>
</head>
<body>
<?php
 $link=mysqli_connect("127.0.0.1","root","123456")
	or die("数据库服务器连接失败!<BR>");
	mysqli_select_db($link,"test") or die("数据库选择失败!<BR>");
	mysqli_query($link,"set names utf8");
   $sql="select *  from news";
  $result=mysqli_query($link,$sql);
 $rows=mysqli_num_rows($result);
// echo $rows;
 if($rows==0){
    
    
  ?>
	  <script>
		  alert('没有新闻存在!');
	  </script>
	<?php
 }
 $pagesize=15;//每页的记录数
 $pagecount=ceil($rows/$pagesize);
 if(!isset($pageno)||$pageno<1){
    
    
 $pageno=1;
 }
 if($pageno>$pagecount){
    
    
 $pageno=$pagecount;
 }
 $offset=($pageno-1)*$pagesize;
 mysqli_data_seek($result,$offset);
 ?>
 <div><h1>新闻查询结果</h1></div>
 <table width="90%" border="1px" align="center">
	 <tr>
		<td><div align="center">标题</div></td>
		<td><div align="center">发布人</div></td>
		<td><div align="center">发布时间</div></td>
		<td><div align="center">图片</div></td>
		<td><div align="center">操作</div></td>
	 </tr>
	 <?php
	   $i=0;
	   while($row=mysqli_fetch_array($result)){
    
    
	   
	   ?>
	   
	   <tr>
			<td><div align="center"><?php echo $row[1]; ?></div></td>
			<td><div align="center"><?php echo $row[4]; ?></div></td>
			 <td><div align="center"><?php echo $row[2]; ?></div></td>
			<td><div align="center"><img src="<?php echo $row[6] ?>" style="width:36px; height:36px;" /></div></td>
			<td><div align="center">
			<a target="#" href="news_xq.php?title=<?php echo $row[0]; ?>">详情</a>
			
			<a target="#" href="news_update.php?title=<?php echo $row[0]; ?>">修改</a>
			<a href="news_delete.php?title=<?php echo $row[0]; ?>" target=
			   "Conframe">删除</a>
			</div></td>
	   </tr>
	   <?php
	   $i=$i+1;
	   //echo $i;
		 if($i==$pagesize){
    
    
		   break;
		 }
	   }
		 mysqli_free_result($result);
		 mysqli_close($link);
	 ?>
	 </table>
	 <div align="center" id="div1" style="margin-bottom:40px">
 [<?php echo $pageno; ?>/<?php echo $pagecount; ?>]
 <?php
 //echo $rows;
 $href=$PHP_SELF;
 if($pageno<>1){
    
    
 ?>
 <a href="news_all_zhang.php?pageno=1">首页</a>
 <a href="news_all_zhang.php?pageno=<?php echo $pageno-1; ?>">上一页</a>
 <?php
 }
 if($pageno<>$pagecount){
    
    
 ?>
 <a href="news_all_zhang.php?pageno=<?php echo $pageno+1; ?>">下一页</a>
 <a href="news_all_zhang.php?pageno=<?php echo $pagecount; ?>">尾页</a>
 <?php
 }
  //echo $rows;
  // echo $pageno;
 ?>
 [共找到<?php echo $rows;?>个记录]

            </div>
</body>
</html>

why?
The guess is that the connection password is incorrect.
After deleting the password, the bug becomes as follows

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, bool given in C:\xampp\htdocs\stiterm\student_insert.php on line 30

Warning: mysqli_data_seek() expects parameter 1 to be mysqli_result, bool given in C:\xampp\htdocs\stiterm\student_insert.php on line 48
���Ų�ѯ���

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in C:\xampp\htdocs\stiterm\student_insert.php on line 61

Warning: mysqli_free_result() expects parameter 1 to be mysqli_result, bool given in C:\xampp\htdocs\stiterm\student_insert.php on line 85
����
������
����ʱ��
ͼƬ
����
[��0ҳ/��0ҳ]
Notice: Undefined variable: PHP_SELF in C:\xampp\htdocs\stiterm\student_insert.php on line 93
��ҳ ��һҳ [���ҵ�����¼]

what is this?
How to fix it?

It may be the problem of mysql connect connection. Check again. If it doesn't work, watch the video to find a solution.

Guess you like

Origin blog.csdn.net/weixin_40945354/article/details/108427152