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
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.
  }

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.