PHP & mysql - please help!

Instead of clogging up posts with off topic discussions, have them here. Keep it clean folks!
Forum rules
By using this site, you agree to our rules. Please see: Terms of Use
Post Reply
User avatar
d_harris
Minor Legend
Posts: 4388
Joined: Thu Apr 15, 2004 3:52 pm
Location: Sunny Brighton
MMOC Member: No

PHP & mysql - please help!

Post 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????

alex_holden
Minor Legend
Posts: 3798
Joined: Tue Jul 25, 2006 9:46 am
Location: Burnley
MMOC Member: No

Post by alex_holden »

You don't appear to be connecting to a database before trying to run a query on it.
ImageImage
Alex Holden - http://www.alexholden.net/
If it doesn't work, you're not hitting it with a big enough hammer.
User avatar
d_harris
Minor Legend
Posts: 4388
Joined: Thu Apr 15, 2004 3:52 pm
Location: Sunny Brighton
MMOC Member: No

Post 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

alainmoran
Minor Addict
Posts: 845
Joined: Tue May 11, 2004 11:56 am
Location: Pantymwyn, Flintshire, Wales
MMOC Member: No

Post by alainmoran »

Dont use php, use .htaccess ... it should be WAY simpler for you to deal with.
User avatar
d_harris
Minor Legend
Posts: 4388
Joined: Thu Apr 15, 2004 3:52 pm
Location: Sunny Brighton
MMOC Member: No

Post by d_harris »

I've been told it has to be PHP & mysql

Matt
Minor Legend
Posts: 3845
Joined: Fri Apr 16, 2004 1:30 pm
Location: Hampshire/Berkshire/Gloucstershire/Herefordshire
MMOC Member: No

Post by Matt »

I wrote a PHP login script at SOC, I am looking for it now for you
Serial Morris Minor Owner and Old Vehicle Nutter
Matt
Minor Legend
Posts: 3845
Joined: Fri Apr 16, 2004 1:30 pm
Location: Hampshire/Berkshire/Gloucstershire/Herefordshire
MMOC Member: No

Post by Matt »

Found and MSN's but you obviously dont want it?
Serial Morris Minor Owner and Old Vehicle Nutter
Post Reply