Hello
Iam getting an error in the pagniation page "Warning: mysql_real_escape_string(): Access denied for user 'username'@'localhost' (using password: NO) in /home/livehuqu/public_html/abcd.com/pptindex.php on line 19 "

Warning: mysql_real_escape_string(): A link to the server could not be established in /home/livehuqu/public_html/abcd.com/pptindex.php on line 19

Iam using the same code in other website and there it was not showing any problems I have checked the code and didn't found any problem in it but now getting this error again and again please help me I need to deliver this website on tomorrow. The code was posted below

<?php include "includes/MysqlConnect.php";
 $con = MysqlConnect::getInstance();
$powerpoint=$con->select("SELECT * FROM `category`ORDER BY `cid`", true);
$result = $con->select("SELECT * FROM `category` ORDER BY `cid` DESC  LIMIT 0,5", true);
  $add= $con->select("SELECT * FROM `advertisement` WHERE addid = 17 ");
 $anamethree=$add['addname'];
 $aimgthree=$add['imgname'];

 $add= $con->select("SELECT * FROM `advertisement` WHERE addid = 16 ");
 $anametwo=$add['addname'];
 $aimgtwo=$add['imgname'];

$adjacents = 3;
$count = $con->select("SELECT COUNT(*) as tot FROM `category` ", false);

$total_pages = $count['tot'];
$targetpage = "pptindex.php";  //your file name  (the name of this file)
$limit = 5;         //how many items to show per page
$page = isset($_GET['page']) ? mysql_real_escape_string($_GET['page']) : 0;
if ($page)
    $start = ($page -1) * $limit;    //first item to display on this page
else
    $start = 0;
//echo "SELECT * FROM `achiev` ORDER BY `achiev_id`  LIMIT ".$start." , ".$limit." ";
$result = $con->select("SELECT * FROM `category` ORDER BY `cid` DESC  LIMIT " . $start . " , " . $limit . " ", true);
if ($page == 0)
    $page = 1;     //if no page var is given, default to 1.
$prev = $page - 1;       //previous page is page - 1
$next = $page + 1;       //next page is page + 1
$lastpage = ceil($total_pages / $limit);  //lastpage is = total pages / items per page, rounded up.
$lpm1 = $lastpage - 1;
$pagination = "";
if ($lastpage > 1) {
    $pagination .= "<div class=\"pagination\">";
    //previous button
    if ($page > 1)
        $pagination.= "<a href=\"$targetpage?page=$prev\" > <span class=\"prev page-numbers\"><span class=\"icon-text left\">&#9666;</span>&nbsp; Previous page&nbsp;</span></a>";
    else
        $pagination.= "<span class=\"prev page-numbers\"><span class=\"icon-text left\">&#9666;</span> &nbsp; Previous page&nbsp;  </span>";

    //pages 
    if ($lastpage < 7 + ($adjacents * 2)) { //not enough pages to bother breaking it up
        for ($counter = 1; $counter <= $lastpage; $counter++) {
            if ($counter == $page)
                $pagination.= "<span class=\"page-numbers current\"> &nbsp; $counter</span>";
            else
                $pagination.= "&nbsp;<a href=\"$targetpage?page=$counter\"><span class=\"page-numbers\"> &nbsp; $counter </span> </a>";
        }
    }
    elseif ($lastpage > 5 + ($adjacents * 2)) { //enough pages to hide some
        //close to beginning; only hide later pages
        if ($page < 1 + ($adjacents * 2)) {
            for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) {
                if ($counter == $page)
                    $pagination.= "<span class=\"page-numbers current\"> &nbsp; $counter</span>";
                else
                    $pagination.= "<a href=\"$targetpage?page=$counter\"> &nbsp; $counter</a>";
            }
            $pagination.= "...";
            $pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
            $pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";
        }
        //in middle; hide some front and some back
        elseif ($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)) {
            $pagination.= "<a href=\"$targetpage?page=1\">1</a>";
            $pagination.= "<a href=\"$targetpage?page=2\">2</a>";
            $pagination.= "...";
            for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++) {
                if ($counter == $page)
                    $pagination.= "<span class=\"page-numbers current\"> &nbsp; $counter</span>";
                else
                    $pagination.= "<a href=\"$targetpage?page=$counter\"> &nbsp; $counter</a>";
            }
            $pagination.= "...";
            $pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
            $pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";
        }
        //close to end; only hide early pages
        else {
            $pagination.= "<a href=\"$targetpage?page=1\">1</a>";
            $pagination.= "<a href=\"$targetpage?page=2\">2</a>";
            $pagination.= "...";
            for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++) {
                if ($counter == $page)
                    $pagination.= "<span class=\"page-numbers current\"> &nbsp; $counter</span>";
                else
                    $pagination.= "<a href=\"$targetpage?page=$counter\"> &nbsp; $counter</a>";
            }
        }
    }

    //next button
    if ($page < $counter - 1)
        $pagination.= "<a href=\"$targetpage?page=$next\"><span class=\"next page-numbers\">&nbsp; Next page<span class=\"icon-text right\">&#9656;</span></span></a>";
    else

        $pagination.= "<span class=\"next page-numbers\">&nbsp; Next page<span class=\"icon-text right\">&#9656;</span></span>";
    $pagination.= "</div>\n";
}





 if (isset($_POST['submit'])) 
 {
     $email=$_POST['e-mail'];
     $name=$_POST['name'];
     if (empty($name)) 
     {
        $error01 = '<font color="red"><b>Enter your name </b></font>';
     }
     if (empty($email)) 
     {
        $error02 = '<font color="red"><b>Enter your email </b></font>';
     }
     else
     {
        $contents = "From :".$email."\n\n"."Name :".$name;
        $to = "info@livecreation.in";
        $subject = "Subscribe recived";

        $from_header = "From: $email";
        if($contents != "")
        {
           mail($to, $subject, $contents, $from_header);
           $error03 = '<font color="green"><b>You are subscribed</b></font>';
        }
    }   
}






?>
<!DOCTYPE HTML>
<!-- BEGIN html -->
<html lang = "en">
    <!-- BEGIN head -->
    <head>
        <title>Presentation</title>

        <!-- Meta Tags -->
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="description" content="" />
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />

        <!-- Favicon -->
        <link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />

        <!-- Stylesheets -->
        <link type="text/css" rel="stylesheet" href="css/reset.css" />
        <link type="text/css" rel="stylesheet" href="css/main-stylesheet.css" />
        <link type="text/css" rel="stylesheet" href="css/lightbox.css" />
        <link type="text/css" rel="stylesheet" href="css/shortcode.css" />
        <link type="text/css" rel="stylesheet" href="css/fonts.css" />
        <link type="text/css" rel="stylesheet" href="css/colors.css" />
        <!--[if lte IE 8]>
        <link type="text/css" rel="stylesheet" href="css/ie-ancient.css" />
        <![endif]-->
        <link type="text/css" rel="stylesheet" href="css/responsive.css" />

                <!-- Author Start -->

     <link rel="stylesheet" href="assets/bootstrap-3.2.0/css/bootstrap.css">


    <script src="assets/js/respond.min.js"></script>
    <script src="assets/js/jquery-1.11.0.js"></script>

    <link rel="stylesheet" href="morphy-buttons/morphy-buttons-vendor.min.css">
    <link rel="stylesheet" href="morphy-buttons/morphy-buttons.min.css">
    <script src="morphy-buttons/morphy-buttons-vendor.min.js"></script>
    <!--<script src="../morphy-buttons/morphy-buttons.min.js"></script>-->
    <script src="morphy-buttons-source/morphy-buttons.js"></script>

        <style>
        @import url(http://fonts.googleapis.com/css?family=Open+Sans:400,300,700,800|Open+Sans+Condensed:300,700|Varela+Round);

        .morph-control {
            padding: 0px;
            /*float: left;*/
            /*clear: left;*/
        }

        .morph-button {
            font-family: 'Titillium Web';
        }
    </style>

        <!-- Author End -->

    <!-- END head -->
    </head>

    <!-- BEGIN body -->
    <body>

        <!-- BEGIN .boxed -->
        <div class="boxed">

            <!-- BEGIN .header -->
            <div class="header">

                <!-- BEGIN .wrapper -->
                <?php include "includes/head.php";?>

            <?php include "includes/menu.php";?>

            <!-- END .header -->
            </div>

            <!-- BEGIN .content -->
            <div class="content">

                <!-- BEGIN .wrapper -->
                <div class="wrapper">
                  <div class="main-content">

                        <!-- BEGIN .main-page -->
                        <div class="main-page left">

                            <!-- BEGIN .double-block -->
                            <div class="double-block">

                                <!-- BEGIN .content-block -->
                                <div class="content-block main right">

                                    <div class="block">
                                        <div class="block-title">
                                            <h2>POPULAR ARTICLES</h2>
                                        </div>
                                        <div class="block-content">
                                         <?php if (!empty($result)) { ?>   
                                            <?php foreach($result as $row){



                                            ?>
                                            <div class="article-big">
                                                <div class="article-photo">
                                                    <a href="pptresult.php?page=<?php echo $row['cid']; ?>" class="hover-effect"><img src="public/images/<?php echo $row['imgname'];?>" width="200" height="130" alt="" /></a>
                                                </div>
                                                <div class="article-content">

                                                    <h2><a href="pptresult.php?page=<?php echo $row['cid']; ?>"><?php echo $row['cname']?></a></h2>

         <?php                                           

      $string=$row['content'];                                              
$string = strip_tags($string);

if (strlen($string) > 300) {

    // truncate string
    $stringCut = substr($string, 0, 300);

    // make sure it ends in a word so assassinate doesn't become ass...
    $string = substr($stringCut, 0, strrpos($stringCut, ' ')); 
}
?>





                                                    <p><?php echo $string;?></p>
                                                    <span class="meta">
                                                        <a href="pptresult.php?page=<?php echo $row['cid']; ?>" class="more">Read more<span class="icon-text">&#9656;</span></a>
                                                    </span>
                                                </div>
                                            </div><?php } ?>



                                             <?php
} else {
    echo "<br /><br />&nbsp;&nbsp;No data found<br /><br /><br /><br />";
}
?>
    <?= "<br />". $pagination. "<br />"; ?>



                                        </div>
                                    </div>

<div class="block">
                                        <div class="banner">
                                                <?php if($anamethree!='null')
                                        {
                                        echo $anamethree;
                                        }
                                        if($aimgthree!='null')
                                        {?>
                                                <?php echo $aimgthree;?><?php } ?>
<a href="contact-us.php" class="ad-link"><span class="icon-text">&#9652;</span>Advertise Here<span class="icon-text">&#9652;</span></a>                                       </div>
                                    </div>


                                <!-- END .content-block -->
                                </div>

                                <!-- BEGIN .content-block -->
                                <div class="content-block left">


                                    <div class="block-title">
                                        <h2>Powerpoint Presentation</h2>
                                        </div>
                                        <ul class="article-list">
                                        <?php foreach($powerpoint as $row) {?>
                                            <li><a href="pptresult.php?page=<?php echo $row['cid']; ?>"><?php echo $row['cname'];?></a></li>
                                            <?php } ?>

                                        </ul>

                                    </div></div>



                                <!-- END .content-block -->
                                </div>


                            <!-- END .double-block -->
                            </div>

                        <!-- END .main-page -->
                        </div>

                        <!-- BEGIN .main-sidebar -->
                        <div class="main-sidebar right">

                            <!-- BEGIN .widget -->
                            <div class="widget">
                                    <?php if($anametwo!='null')
                                        {
                                        echo $anametwo;
                                        }
                                        if($aimgtwo!='null')
                                        {?>
                                                <?php echo $aimgtwo;?><?php } ?>
                                <a href="contact-us.php" class="ad-link"><span class="icon-text">&#9652;</span>Advertise Here<span class="icon-text">&#9652;</span></a>
                            <!-- END .widget -->
                            </div>

                            <!-- BEGIN .widget -->
                                        <?php include "includes/social.php";?>


                            <!-- BEGIN .widget -->
                            <?php include "includes/latestnews.php"?>
                              <?php include "includes/healthedu.php";?>
                            <!-- BEGIN .widget -->
                            <div class="widget">
                                <h3>Subscribe Mailing List</h3>
                                <div class="mailing-list">
                                    <p>By subscribing You will recieve our latest news. Your information will not be shared with anyone.</p>
                                    <hr />
                                    <div >
                                  <!--  <script> 
                                    function sendConfirm()
                                    alert ("<span class="icon-text">&#128077;('Gear Success !,Everything went well, You are now subscribed !');</span>");
                                    </script>-->



                                    <script>
                                    function sendConfirm()
                                    alert("U are subscribed");
                                    </script>




                                    </div>
                                    <!--<div class="info-message success">
                                        <span class="icon-text">&#128077;</span>
                                        <b>Gear Success !</b>
                                        <p>Everything went well, You are now subscribed !</p>
                                    </div>

                                    -->





                                    <div class="subscribe-block">
                                        <form action="pptindex.php" method="post">
                                         <?php echo isset($error03) ? '<span>' . $error03 . '</span><br /><br />' : ''; ?> 
                                          <?php echo isset($error01) ? '<span>' . $error01 . '</span><br /><br />' : ''; ?> 
                                            <p><input type="text" value="" name="name" placeholder="Your name" /></p>
                                             <?php echo isset($error02) ? '<span>' . $error02 . '</span><br /><br />' : ''; ?> 
                                            <p><input type="text" value="" name="e-mail" placeholder="Your e-mail" /></p>
                                            <p><a href="#" onClick="return sendConfirm();"><input type="submit" value="Subscribe" name="submit" class="button" /></a></p>
                                        </form>
                                    </div>
                                </div>
                            <!-- END .widget -->
                            </div>

                        <!-- END .main-sidebar -->
                        </div>

                        <div class="clear-float"></div>

                  </div>

                <!-- END .wrapper -->
              </div>

            <!-- BEGIN .content -->
            </div>

            <!-- BEGIN .footer -->
                        <?php include "includes/footer.php";?>


        <!-- END .boxed -->
        </div>

        <!-- Scripts -->
        <script type="text/javascript" src="jscript/jquery-latest.min.js"></script>
        <script type="text/javascript" src="jscript/theme-scripts.js"></script>
        <script type="text/javascript" src="jscript/lightbox.js"></script>

    <!-- END body -->
    </body>
<!-- END html -->
</html>

Access denied means you need to look at your connection string. You're pointing to the wrong database, have the user name wrong or that user doesn't have access to that particular database. Something about your connection attempt is the cause of the error.

hericles, you are right I have checked the connection and there I can seen some mistake. the pagination was take by some tutorial website and I have copied the code also in my project while copying I didn't removed the line mysqli to mysql so it was the problem in the connection. Any way thank you for your reply.

$connecDB = mysqli_connect($db_host, $db_username, $db_password,$db_name)or die('could not connect to database');
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.