PHP Login script

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
sagat
Forum Newbie
Posts: 3
Joined: Tue Jan 13, 2004 4:56 pm

PHP Login script

Post by sagat »

<form method="post" action="process.php">
Username
<input type="text" name="user" />
<br />
Password
<input type="password" name="pass" />
<br />
<input type="submit" name="submit" value="Login" />
</form>
<?
//get variables from login screen.mdb
$user = $_POST['user'];
$pass = $_POST['pass'];

if (odbc_num_rows($query)) {
header("Location: process.php");
exit();
} else {
echo "you can't log in.";
}
?>

I have done the process PHP but how can i validate users? When i run the code it comes up with the following errors:

Warning: odbc_num_rows(): supplied argument is not a valid ODBC result resource in c:\phpdev5\www\tmpa3fcbrhqz1.php on line 15
you can't log in.

where am i going wrong?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You haven't actually queried the database for anything but are trying to count rows of a query that doesn't exist. Basically you're missing a bunch of code.

Mac
sagat
Forum Newbie
Posts: 3
Joined: Tue Jan 13, 2004 4:56 pm

Post by sagat »

ps can u give me a sample query? thanx
User avatar
phpcoder
Forum Contributor
Posts: 158
Joined: Sat Nov 02, 2002 1:18 pm
Location: Manchester, UK

Post by phpcoder »

Code: Select all

$query="select password from table_name where user_name='%s'";
$result=mysql_query(sprintf($query,$_POST&#1111;'username']));
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Basically you need to connect to the database, then query the database.
[php_man]odbc_connect[/php_man]()
[php_man]odbc_exec[/php_man]()

Google gives you:
http://www.w3schools.com/php/php_db_odbc.asp

Mac
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

phpcoder wrote:

Code: Select all

$query="select password from table_name where user_name='%s'";
$result=mysql_query(sprintf($query,$_POST&#1111;'username']));
That won't work - he's trying to query an Access database not MySQL, not that it's stated in the current topic but it was in a previous thread so it's an easy mistake to make.
viewtopic.php?p=80865

Mac
Post Reply