Jump to content

[SOLVED] PHP/MySQL problem


CrazeD

Recommended Posts

I get this error:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\web\login.php on line 19

 

Here is my code:

<?php

include('_mysql.php');

function gettemplate($template,$endung="html") {
    $templatefolder = "templates";
    return str_replace("\"","\\\"",implode("",file($templatefolder."/".$template.".".$endung)));
}


if (isset ($_POST['submit'])) {
$username = $_POST['username'];
$pass = $_POST['password'];
$enc_pass = md5($pass);

if($username != "" && $password != ""){
	$query = "SELECT * FROM users WHERE username='$username' AND user_password='$enc_pass'";
	$gay=mysql_query($query);		
	$num=mysql_num_rows($gay);
	if($num > 0) {
		$_SESSION['username'] = $username;
		$_SESSION['loggedin'] = 1;
		$_SESSION['user_level'] = @mysql_result($result, 0, user_level);
		eval ("\$login = \"".gettemplate("loginsuccessful")."\";");

	} else { // Did not much

		eval ("\$loginerror = \"".gettemplate("login_enterunamepwd")."\";");

		}		

	} else { // Enter both a username and password

		eval ("\$loginerror = \"".gettemplate("login_enterunamepwd")."\";");
	}

} else { // Submit not entered

header ('Location: index.php');

}

mysql_close();

?>

This is a login script.

 

This worked for me before, but now I get this error. What is the problem?

 

Thanks.

 

EDIT: Nevermind I got it.

 

I spent all night trying to fix it and then I post for help and right as I do I figure it out. :/

Link to comment
https://forums.phpfreaks.com/topic/48150-solved-phpmysql-problem/
Share on other sites

What is the problem?

 

The problem is your query is failing. More to the point, you fail to check your query before attempting to use it. The most basic general syntax for a SELECT query should always be at least.

 

<?php

  if ($result = mysql_query($sql)) { // where $sql holds your sql statement.
    if (mysql_num_rows($result)) {
      // $result now holds valid result.
    } else {
      // No results found, handle error.
    }
  } else {
    // query failed, handle error.
  }

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.