-2

I'm new to this.Even though I checked php.net for the functions mysql_fetch_row() and mysql_fetch_result() I keep getting warnings

expects parameter 1 to be resource, boolean given

  <?php

 //code

 $sql1="SELECT * FROM $tblname WHERE USERNAME='$myusername' and    PASSWORD='$mypassword'";
 $result1=mysql_query($sql1);

 // Mysql_num_row is counting table row
 $count=mysql_num_rows($result1);
 // If result matched $myusername and $mypassword, table row must be 1 row

 if($count==1)
 {

 $sql2="SELECT CLIENT_ID FROM $tblname WHERE USERNAME='$myusername' and PASSWORD='$mypassword'";
 $result2=mysql_query($sql2); //THIS LINE!!!
 $cid=mysql_result($result2,$row2); //THIS LINE!!!

 // Register info
 $_SESSION['sessname'] = "$myusername";
 $_SESSION['sesspwd'] = "$mypassword";
 $_SESSION['sessid'] = "$cid";
 $_SESSION['sessaccid'] = "$accid";

//more code
 ?>
BenMorel
  • 34,448
  • 50
  • 182
  • 322
  • Please search the site and check the possible dupes list when typing in the title of your question. – PeeHaa Jun 10 '13 at 09:32
  • 1
    possible duplicate of [ERROR: Warning: mysql\_num\_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\...\....php on line 19](http://stackoverflow.com/questions/6045476/error-warning-mysql-num-rows-expects-parameter-1-to-be-resource-boolean-giv) – symcbean Jun 10 '13 at 09:33
  • If you're checking PHP.net for the functions, you'll already have seen the note on the manual pages which say that all the `mysql_xxx()` functions are deprecated and not recommended for use. If you're new to this, you should really be considering learning to use the up-to-date PDO library, rather than the old mysql library which means your new skills are out-of-date before you've even learnt them. – Spudley Jun 10 '13 at 10:00
  • I'm new because the total amount of days I've worked with php and mysql is barely 30.Two years ago I had a project where I used php mysql and now I have another project but so little time and I'm choking, so I'm using the few things I know from the last project. You are right all of you, I appreciate your comments and I understand because what you all say is true. – user2470282 Jun 29 '13 at 11:48

1 Answers1

1

$result2 is returning you a boolean (meaning that an error is occurred in your select) and, so, you're passing this boolean to mysql_result() instead of a resource.

This is the returning value, taken from documentation

For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.

You should modify your code as follow

[...]
$sql2="SELECT CLIENT_ID FROM $tblname WHERE USERNAME='$myusername' and PASSWORD='$mypassword'";
$result2=mysql_query($sql2);
if($result2)
{
  $cid=mysql_result($result2,$row2); //THIS LINE!!!
}
else
{
//do some error handling
}
[...]

Moreover, you shouldn't use mysql_* functions because are deprecated. Use PDO or mysqli_* instead

DonCallisto
  • 29,419
  • 9
  • 72
  • 100