用户访问被拒绝' XXX' @' localhost' (使用密码:否)

时间:2015-11-03 13:08:26

标签: php mysql

我在搜索表单上搜索任何内容时会出现此错误。

我附上搜索页面代码。

<?php
include_once('header.php');
$p='';
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
    if (isset($_POST['sword'])){

            echo $sword=trim($_POST['sword']) ;



    }
}

            $sql="SELECT * FROM news where status=1 and title like \"%$sword%\"  ORDER BY n_id DESC";
$rs = mysql_query($sql)or die(mysql_error());
$nr = @mysql_num_rows($rs);

;


?>


<style type="text/css">


.createdate{ color:#999; font-size:12px; font-weight:normal;}
    .section{
    float:right;
    height:60px;
    overflow:hidden;
    padding:5px;
    text-align:right;
    direction:rtl;  
    width: 335px;
    padding-bottom:13px;
    border-bottom:1px dotted #CCC;
    margin-right:10px;
}
.section #linkText a:link, .section #linkText a:visited{
font-family: almtwerd,helvetica,arial,tahoma;
font-size: 11px;
font-weight: normal;
    text-align:right;
    direction:rtl;
    color:#333;
    text-decoration:none;
}


.section #linkText a:hover{
font-family: almtwerd,helvetica,arial,tahoma;
font-size: 11px;
font-weight: normal;
    text-align:right;
    direction:rtl;
    color:#036;
    text-decoration:none;
}

.section #brief {
font-family: almtwerd,helvetica,arial,tahoma;
font-size: 8px;
font-weight: normal;
    text-align:right;
    direction:rtl;
    color:#000;
    font-weight:normal;
    overflow:hidden;
    padding-bottom:5px;
}

.section #brief img {
    border:1px solid #CCC;
    padding:3px;
    float:left;
    margin-right:5px;

}

.section img {
    border:1px solid #CCC;
    padding:3px;
    float:right;
    margin-left:5px;
width: 80px;
height: 60px;
}
.section:hover{
    background-color:#d1dde5;
}









div.pagination {
 padding: 3px;
 margin: 3px;

 direction:rtl;
}
div.pagination a {
 padding: 2px 5px 2px 5px;
 margin: 2px;
 border: 1px solid #AAAADD;

 text-decoration: none; /* no underline */
 color: #000099;
}
div.pagination a:hover, div.pagination a:active {
 border: 1px solid #003d00;
 color: #003d00;
}
div.pagination span.current {
 padding: 2px 5px 2px 5px;
 margin: 2px;
  border: 1px solid #003d00;

  font-weight: bold;
  background-color: #dbfd9b;
  color: #003d00;
 }
 div.pagination span.disabled {
  padding: 2px 5px 2px 5px;
  margin: 2px;
  border: 1px solid #EEE;

  color: #DDD;
 } 
    ul.pagination li.details{
       color:#FFA200;
    }

    ul.pagination li a
    {
               color: #fff;
        background:#699613;
        background:-moz-linear-gradient(top,#87AB19,#699613);
        background:-webkit-gradient(linear,0 0,0 100%,from(#87AB19),to(#699613));
            float:right;
    text-align:right;
    font-size:14px;
    font-weight:normal;
    }

    ul.pagination li
    {
        padding-bottom:1px;
    }

    ul.pagination li a:hover,
    ul.pagination li a.current
    {   
        color:#FFFFFF;
        box-shadow:0px 1px #E7E7E7;
        -moz-box-shadow:0px 1px #E7E7E7;
        -webkit-box-shadow:0px 1px #E7E7E7;       
    }

    ul.pagination li a:hover,
    ul.pagination li a.current
    {
        color:#893A00;
        text-shadow:0px 1px #FFEF42;
        border-color:#FFA200;
        background:#FFC800;
        background:-moz-linear-gradient(top,#FFFFFF 1px,#FFEA01 1px,#FFC800);
        background:-webkit-gradient(linear,0 0,0 100%,color-stop(0.02,#FFFFFF),color-stop(0.02,#FFEA01),color-stop(1,#FFC800));
    } 










</style>

<table border="0" dir="rtl" width="990px">
<tr>
<td width="730px" valign="top">
     <div class="cat-box-content" style="margin: 5px;">
<h2 class="title" style="border-color: Default;"> <a href="index.htm"> الرئيسية</a> &raquo;
<a>نتائج البحث </a>
</h2>

   <div style="clear: both;"></div>






    <?php



        $adjacents = 3;




        //$total_pages = $total_pages[num];

        $targetpage = "search.htm";
        $limit = 20;

        if($p)
        $start = ($p-1) * $limit;
        else
        $start = 0;



        if ($p == 0) $p = 1;
        $prev = $p - 1;
        $next = $p + 1;
        $lastpage = ceil($total_pages/$limit);

        $lpm1 = $lastpage - 1;

        $pagination = "";
        if($lastpage > 1)
        {
            $pagination .= "<div class=\"pagination\">";
            if ($p > 1)
            $pagination.= "<a href=\"$targetpage?p=$prev\">« السابق</a>";
            else
            $pagination.= "<span class=\"disabled\">« السابق</span>";

            if ($lastpage < 7 + ($adjacents * 2))
            {
                for ($counter = 1; $counter <= $lastpage; $counter++)
                {
                    if ($counter == $p)
                    $pagination.= "<span class=\"current\">$counter</span>";
                    else
                    $pagination.= "<a href=\"$targetpage?sid=$s_id&&p=$counter\">$counter</a>";
                }
            }
            elseif($lastpage > 5 + ($adjacents * 2))
            {
                if($p < 1 + ($adjacents * 2))
                {
                    for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
                    {
                        if ($counter == $p)
                        $pagination.= "<span class=\"current\">$counter</span>";
                        else
                        $pagination.= "<a href=\"$targetpage?sid=$s_id&&p=$counter\">$counter</a>";
                    }
                    $pagination.= "...";
                    $pagination.= "<a href=\"$targetpage?sid=$s_id&&p=$lpm1\">$lpm1</a>";
                    $pagination.= "<a href=\"$targetpage?sid=$s_id&&p=$lastpage\">$lastpage</a>";
                }

                elseif($lastpage - ($adjacents * 2) > $p && $p > ($adjacents * 2))
                {
                    $pagination.= "<a href=\"$targetpage?sid=$s_id&&p=1\">1</a>";
                    $pagination.= "<a href=\"$targetpage?sid=$s_id&&p=2\">2</a>";
                    $pagination.= "...";
                    for ($counter = $p - $adjacents; $counter <= $p + $adjacents; $counter++)
                    {
                        if ($counter == $p)
                        $pagination.= "<span class=\"current\">$counter</span>";
                        else
                        $pagination.= "<a href=\"$targetpage?sid=$s_id&&p=$counter\">$counter</a>";
                    }
                    $pagination.= "...";
                    $pagination.= "<a href=\"$targetpage?sid=$s_id&&p=$lpm1\">$lpm1</a>";
                    $pagination.= "<a href=\"$targetpage?sid=$s_id&&p=$lastpage\">$lastpage</a>";
                }
                else
                {
                    $pagination.= "<a href=\"$targetpage?sid=$s_id&&p=1\">1</a>";
                    $pagination.= "<a href=\"$targetpage?sid=$s_id&&p=2\">2</a>";
                    $pagination.= "...";
                    for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
                    {
                        if ($counter == $p)
                        $pagination.= "<span class=\"current\">$counter</span>";
                        else
                        $pagination.= "<a href=\"$targetpage?sid=$s_id&&p=$counter\">$counter</a>";
                    }
                }
            }
            if ($p < $counter - 1)
            $pagination.= "&nbsp;&nbsp;<a href=\"$targetpage?sid=$s_id&&p=$next\">التالي»</a>";
            else
            $pagination.= "<span class=\"disabled\">التالي»</span>";
            $pagination.= "</div>\n";
        }
        $sql = "SELECT * FROM news where status=1 and title like \"%$sword%\"  ORDER BY n_id DESC LIMIT $start, $limit";
        $result = mysql_query($sql);
        $upload="upload/";
        ?> <?php
        $count=mysql_num_rows($result);
        echo "<br/><b><font style='font-family: almtwerd,helvetica,arial,tahoma;
font-size: 11px;
font-weight: normal;'>هناك&nbsp;".$count."&nbsp; من النتائج</font></b><br /> <hr />";
        while($row=mysql_fetch_array($result)){
            $text = substr($row[3],0,400);
            $text=strip_tags($text);
            ?>

 <div class="section">
               <img src="<?php echo $site_url;?>upload/small/<?php echo $row[image];?>" width="80" height="60"  />
                <div id="linkText">

                  <a href="news-<?php echo $row[n_id]?>.htm">
                   <?php echo $row[title]?>               </a>

                </div>
                <div id="brief"></div></div>



        <?php
        }
        ?>






















   <div style="clear: both;"></div>

</div> 
</td>
<td width="260px" valign="top"><?php @include_once('left.php')?></td>
</tr>
</table>
<?php include('footer.php');?>

1 个答案:

答案 0 :(得分:0)

我认为XXX不是root用户。

因此,您必须在数据库中为您的select用户添加XXX权限。

例如:

GRANT ALL ON yourDbName.* TO 'XXX'@'localhost';
flush privileges;