-1

I have an error in my mysql statement and i am not able to understand whats wrong with it. I am getting following warning

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\website-template-40\website-template-40\employed.php on line 166 and after using mysql_error

i got following error:- what a error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where designation='employed'' at line 1

 <?php

    $q="select count(*) \"total\"  from tblregistration where designation='employed'";
    $ros=mysql_query($q) or die('error1'.mysql_error());
    $row=(mysql_fetch_array($ros));
    $total=$row['total'];

    $dis=8;
    $total_page=ceil($total/$dis);

    $page_cur=(isset($_GET['page']))?$_GET['page']:1;
    $k=($page_cur-1)*$dis;
    $q11="select * from tblregistration limit $k,$dis where designation='employed'";

    $ros1=mysql_query($q11) or die('what a error'.mysql_error());

    $i=2;
    while($row1=mysql_fetch_array($ros1))
    {
        if($i==2)  
      { 
        echo '<tr>';
        $i=0;
      }

        ?>  <td><img src="upload/<?php echo $row1['image'];?>" width="100px" height="100px;" /></td>
            <td><?php echo $row1['name'];?><br />
                <?php echo $row1['designation'];?><br />
                <?php echo $row1['contactno'];?><br />
                <?php echo $row1['emailid'];?><br />

            </td>
     <?php  
       $i++;
       if($i==2)
       {
      echo '</tr>';
       } 
    }  ?>

2 Answers2

0

The LIMIT keyword should come at the end and not before the WHERE clause.

The right way..

select * from `tblregistration` where `designation`='employed' LIMIT '$k','$dis'

This(mysql_*) extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used. Switching to PreparedStatements is even more better to ward off SQL Injection attacks !

Shankar Narayana Damodaran
  • 66,874
  • 43
  • 94
  • 124
0

1) sql query structure:

SELECT field1 [,"field2",etc]
FROM table
[WHERE "condition"]
[LIMIT "limit"]

2) you can not use die in a string assignment in this line:

$q11="select * from tblregistration limit $k,$dis where designation='employed'" or die('what a error'.mysql_error());

change those lines:

 $q11="select * from tblregistration limit $k,$dis where designation='employed'" or die('what a error'.mysql_error());

    $ros1=mysql_query($q11);

to:

   $q11="select * from tblregistration  where designation='employed' limit $k,$dis"; 
    $ros1=mysql_query($q11) or die('what a error'.mysql_error());
Awlad Liton
  • 9,260
  • 2
  • 26
  • 50