Page 1 of 1

PHP Login script

Posted: Wed Jan 14, 2004 11:56 am
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?

Posted: Wed Jan 14, 2004 11:58 am
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

Posted: Wed Jan 14, 2004 12:00 pm
by sagat
ps can u give me a sample query? thanx

Posted: Wed Jan 14, 2004 12:09 pm
by phpcoder

Code: Select all

$query="select password from table_name where user_name='%s'";
$result=mysql_query(sprintf($query,$_POST&#1111;'username']));

Posted: Wed Jan 14, 2004 12:10 pm
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

Posted: Wed Jan 14, 2004 12:11 pm
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