Page 1 of 1

PHP & mysql - please help!

Posted: Mon May 04, 2009 5:23 pm
by d_harris
I've tried googling and googling for this but can't seem to come up with any luck. I am trying to write a really simple username / password verifier in PHP. wondering if there are any webby type people on here I thought I would give this a go - I am really really really stucked....

What I have is:

Code: Select all

<?php

$login = $_POST['login'];
$password = $_POST['password'];

$q = mysql_query("SELECT m_pwd FROM member WHERE m_uname=='$login'");
$db_pass = mysql_result($q, 0);

if($password == $db_pass)
{
    echo "Win";
}

else echo "Fail";

?>
Which was nicked off google.

I always get the error

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in F:\xampp\htdocs\SHR\checklogin.php on line 30 (line 30 being $db_pass = mysql_result($q, 0)

And it always comes up with "win" whatever happens. Suggestions please????

Posted: Mon May 04, 2009 5:29 pm
by alex_holden
You don't appear to be connecting to a database before trying to run a query on it.

Posted: Mon May 04, 2009 5:39 pm
by d_harris
thats elsewhere in the code.

Code: Select all

<!DOCTYPE html
     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<?php
include 'top.php';
include 'conn.php';
?>
<html xmlns="http://www.w3.org/1999/xhtml"
          xml:lang="en-GB" lang="en-GB">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>login</title>
    <link rel="stylesheet" type="text/css" href="form_styles.css" />
  </head>
  <body>
		<h1>Member Login</h1>
		<p>Logging you in,  hang tight......
		
		
		
		
		<span class="name">
						
			<?php

$login = $_POST['login'];
$password = $_POST['password'];

$q = mysql_query("SELECT m_pwd FROM member WHERE m_uname=='$login'");
\\$db_pass = mysql_result($q, 0);

if($password == $db_pass)
{ 
    echo "Win";
}

else echo "Fail";

?>

			</p>
  </body>
</html>
<?php
include 'bottom.php';
?>
the connection is in conn.php

Posted: Mon May 04, 2009 9:49 pm
by alainmoran
Dont use php, use .htaccess ... it should be WAY simpler for you to deal with.

Posted: Mon May 04, 2009 9:54 pm
by d_harris
I've been told it has to be PHP & mysql

Posted: Mon May 04, 2009 10:09 pm
by Matt
I wrote a PHP login script at SOC, I am looking for it now for you

Posted: Mon May 04, 2009 10:12 pm
by Matt
Found and MSN's but you obviously dont want it?