php + mysql query error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tbtphoenix
Forum Newbie
Posts: 2
Joined: Mon Nov 29, 2010 5:05 pm

php + mysql query error

Post by tbtphoenix »

I have a form on my index page for logging into a site that i am creating. I want to be able to take information from the form using post, the code for my form looks like this
[text]
<form class='align_right' action='phppages/login.php' method='post'>
<table id='login'>
<tr><th class='text_align_center'>LOGIN</th></tr>
<tr><td>Username:</td><td><input type='text' name='username' /></td></tr>
<tr><td>Password:</td><td><input type='password' name='userpass' /></td></tr>
<tr><td class='align_center'><input type='submit' value='Login' /></td></tr>
</table>
</form>
[/text]

I need a way to basically do this:

Code: Select all

include 'config.php';
$con = mysql_connect($serverloc,$serveruser,$serverpass);
if (!con)
	{
	die('Could not connect: ' . mysql_error());
	}
	mysql_select_db("ntbwordpress", $con);
		$result = mysql_query("SELECT FROM Users WHERE UserName = '$_POST[username]' AND Password = '$_POST[userpass]'");
		$row = mysql_fetch_array($result);
		if ($row['UserName'] = $_POST['username'] && $row['Password'] = $_POST['userpass'])
			{
			echo "you are sucessfully logged into " . $_POST['username'] . "'s account";
			}
		else if ($row['UserName'] != '$_POST[username]')
			{
			echo "Password/Username is incorrect";
			}
			mysql_close($con);
?>
the error i get is :
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
any help would be great, thank you, i am fairly new to this
tbtphoenix
Forum Newbie
Posts: 2
Joined: Mon Nov 29, 2010 5:05 pm

Re: php + mysql query error

Post by tbtphoenix »

nevermind I got a better way to do it from http://phpeasystep.com/phptu/6.html
Post Reply