Need some help with Login script,
Posted: Fri Oct 29, 2010 1:01 pm
Code: Select all
<?php
$tbl_name="login"; // Table name
// Connect to databse.
$databs = 'c:\database\UsernameDB.mdb';
$dbConnect = odbc_connect("Driver={Microsoft Access Driver (*.mdb)}; DBQ=$databs","","") or die ("Error opening database .... use the browsers BACK button");
// Get username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// Build SQL Query
$sql = "SELECT top 100 * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result = odbc_exec($dbConnect, $sql)
// Look for Matching table row
$count = odbc_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1)
{
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
header("location:login_success.php");
}
else
{
echo "Wrong Username or Password";
}
// close the connection
odbc_close($dbConnect);
?>I keep getting an error on line 18 ($count = odbc_num_rows($result);) I can't see the problem. I have found that odbc_num_rows will return a -1 instead of 1 for access but the issue should be fixed by adding the "top 100" into the SQL statment.
Any help would be greatfull. Trax