yddib Posted March 19, 2008 Share Posted March 19, 2008 I want different users to be directed to different pages. I am having difficulty with it. Any suggestions would be appreciated. ??? <body> <?php // Get the data collected from the user $Username =$_POST["username"]; $Password =$_POST["password"]; //create an instance of the ADO connection object $conn = new COM ("ADODB.Connection") or die("Cannot start ADO"); //define connection string, specify database driver $connStr = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Databases\employees.mdb"; //Open the connection to the database $conn->open($connStr); echo "Connection Open<br>"; $SQL = "SELECT username, password FROM accounts WHERE username = '$Username' AND password = '$Password'"; ?> </body> Link to comment https://forums.phpfreaks.com/topic/96908-login-with-ms-access/ Share on other sites More sharing options...
micah1701 Posted March 19, 2008 Share Posted March 19, 2008 now that you've opened the connection and created an SQL statement, you have to execute that statement and return your results. your next line should be something like: $results = odbc_exec($conn, $sql); now $results is an array of your results. you can do print_r($results) to see what you have. check out http://us2.php.net/odbc_exec (the manual) and read up. to answer your question... this is what your code should look something like: <?php <?php // Get the data collected from the user $Username =$_POST["username"]; $Password =$_POST["password"]; //create an instance of the ADO connection object $conn = new COM ("ADODB.Connection") or die("Cannot start ADO"); //define connection string, specify database driver $connStr = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Databases\employees.mdb"; //Open the connection to the database $conn->open($connStr); echo "Connection Open"; $SQL = "SELECT username, password FROM accounts WHERE username = '$Username' AND password = '$Password'"; $results = odbc_exec($conn, $sql); if(odbc_num_rows($results) == 1){ header("Location: /path/to/new_page.php"); //forward user to new page exit(); }else{ // zero or more then one result found echo "sorry, your username and password weren't found"; } ?> Link to comment https://forums.phpfreaks.com/topic/96908-login-with-ms-access/#findComment-495897 Share on other sites More sharing options...
yddib Posted March 19, 2008 Author Share Posted March 19, 2008 I changed some things but it is still not working. It is saying that the username and password weren't found. The records I entered are in my database. Thank you for your help <body> <?php // Get the data collected from the user $Username =$_POST["Username"]; $Pass =$_POST["Pass"]; ///create an instance of the ADO connection object $conn = new COM ("ADODB.Connection") or die("Cannot start ADO"); //define connection string, specify database driver $connStr = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=c:Databases\employees.mdb"; //Open the connection to the database $conn->open($connStr); echo "Connection Open<br>"; $SQL = "SELECT 'Username', 'Password' FROM Details WHERE Username = '$Username' AND Pass = '$Pass'"; $results = odbc_exec($conn, $sql); if(odbc_num_rows($results) == 1){ header("Location: manager1.php"); //forward user to new page exit(); } else{ // zero or more then one result found echo "sorry, your username and password weren't found"; } ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/96908-login-with-ms-access/#findComment-495923 Share on other sites More sharing options...
micah1701 Posted March 19, 2008 Share Posted March 19, 2008 try diagnosing to see where the problem is. modify the odbc_exec() line like this: <?php $results = odbc_exec($conn, $sql) or die(odbc_error()); // show description of error if there was a problem ?> if its a problem with the query, that should help. if that doesn't help it means the problem is in interpreting the results. take out the if/then statement checking for rows returns and just put: <?php print_r($results); ?> it will return an array of the results you've just queried. That could help you diagnos where the problem lies as well. good luck Link to comment https://forums.phpfreaks.com/topic/96908-login-with-ms-access/#findComment-495957 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.