Problem in executing sql query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bandy
    New Member
    • Mar 2010
    • 25

    Problem in executing sql query

    Hi there,
    I am trying to execute a query on database but it's giving error as:
    Warning: mysql_fetch_row (): supplied argument is not a valid MySQL result resource in C:\wamp\www\201 00519\HonestFol lowers.com\desi gn\datagraph.ph p on line 21.
    and also shows Resource id #46.
    The connection is successful, database is also selected.
    What is the problem? can U help me on this,
    help will be greatly appreciated.
    Here is my code:
    Code:
    if($con = mysql_connect('localhost', 'Rushi', 'bhanage'))
    	echo "connection successful!!<br>";
    else
        die (mysql_error());
    	 
     $db = mysql_select_db("rohit25_honestfollowers", $con);
     	echo "Database successfully selected!!<br>";
    $sql = mysql_query("select * from usersearchmaster") or die (mysql_error());
    echo $sql;
     $dishf = array();
      while($res = mysql_fetch_row($exec))
      {
      	echo $dishf[] = $res[DishoestFollower]."<br>";
      }
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    You are using the wrong variable for the result resource
    Code:
    $sql = mysql_query("select * from usersearchmaster") or die (mysql_error()); 
    echo $sql; 
     $dishf = array(); 
      while($res = mysql_fetch_row($exec))
    $exec instead of $sql.

    Comment

    • bandy
      New Member
      • Mar 2010
      • 25

      #3
      Originally posted by code green
      You are using the wrong variable for the result resource
      Code:
      $sql = mysql_query("select * from usersearchmaster") or die (mysql_error()); 
      echo $sql; 
       $dishf = array(); 
        while($res = mysql_fetch_row($exec))
      $exec instead of $sql.
      Hi there,
      extremely sorry, it happened while cleaning code, but I tried it with:
      Code:
          $res = mysql_fetch_row($sql);
      but no change in error.

      Comment

      • aung1986
        New Member
        • May 2010
        • 2

        #4
        DishoestFollowe r is the right field name in the table.
        first you test output data with"echo $res[DishoestFollowe r]."<br>";"
        and then you should add to array.

        Comment

        • bandy
          New Member
          • Mar 2010
          • 25

          #5
          Originally posted by aung1986
          DishoestFollowe r is the right field name in the table.
          first you test output data with"echo $res[DishoestFollowe r]."<br>";"
          and then you should add to array.
          I got my problem solved. Actually problem was with
          mysql_fetch_row ($sql);
          when I went with array i.e:
          mysql_fetch_arr ay($sql)
          I got expectd result.

          Thank you all.

          Comment

          Working...