-4

Possible Duplicate:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result

When I try to fetch a MySQL recordset as objects, I receive the following warning:

Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in/home/bbbbb/public_html/curl.php on line 24

How can I resolve this?

Here is the script:

<?php
$mysqlhost="....."; // Host name 
$mysqluser="...."; // Mysql username 
$mysqlpasswd="....."; // Mysql password 
$mysqldbname="......"; // Database name 

//$post_item[]='username='.$_POST['username'];
$username=$_POST['username']; 

$con = @mysql_pconnect($mysqlhost, $mysqluser, $mysqlpasswd);
  if(!$con) {
echo "Mysql error: " . mysql_error();
  exit();
  }

mysql_select_db($mysqldbname);

$mysqlt = "dle_users"; ///Your table////

$abfrage = "SELECT * FROM `$mysqlt`";
$ergebnis = mysql_query($abfrage);
$tb = array();
while($row = mysql_fetch_object($ergebnis))
  {
$tb[] = $row->username;
 }
if (!in_array($username, $tb)) {
return false;
echo "Wrong Username or Password";
  }
 else {
echo "Login Successful";
 return true;
}
?>
Community
  • 1
  • 1
Pds Ir
  • 83
  • 1
  • 1
  • 6
  • 2
    This has been asked/answered about 5 kajillion times on this site. – Marc B May 21 '12 at 14:08
  • This question shows no research effort. Also the `pleas help i really need this` is spam once you write it more than a dozen times. Furthermore, this looks like homework. – Valentin Brasso May 21 '12 at 14:14
  • 1
    Don't use `mysql_` functions. Don't extract a whole table and loop through it to find a result (take a look at [`WHERE`](http://en.wikipedia.org/wiki/Where_(SQL)). Don't `echo` after a `return`. Improve your indentation to improve readability. And of course, welcome to Stack Overflow. _Sidenote: you're lucky don't have to expect the obligatory 'sql injection' posts here_ – CodeCaster May 21 '12 at 14:15

1 Answers1

1

Try:

...
$ergebnis = mysql_query($abfrage);
if (false === $ergebnis){
  echo mysql_error(); 
  exit; 
}
...

And show the result.

erdeszt
  • 799
  • 5
  • 12
  • nice thank you. and i have other question if i want to check both username and password what cod must be added or edited :D – Pds Ir May 21 '12 at 14:59
  • There are millions of tutorials in this subject on the internet, try google some and ask again if you stuck. – erdeszt May 21 '12 at 15:05
  • Thank you for reply but i cant find useful tutorials for my problem if possible help me here – Pds Ir May 21 '12 at 18:36
  • Here's the query "select * from dle_users where username = '" . mysql_real_escape_string($username) . "' and password = '" . mysql_real_escape_string($password) . "' limit 1" If it gives a row than password and username is correct. (Don't forget the hashing of the password if you used it when it was created.) – erdeszt May 22 '12 at 08:00