Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
| Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 7th, 2004, 03:41 PM
Registered User
 
Join Date: Oct 2004
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default session login with access db

first i'd like to thank you guys on these forums for being so helpful, i've been able to fix almost every issue with my current project. now that i'm coming to the home stretch this is where i'm having the most issues. i'm tryin to make a login using a access db but its not reposonding, it just reloads the forms basically and doesn't say if password failed or not. here is the code. it looks crappy i know, i am a beginner

Code:
<?php
//auth_user.php

function auth_user($userid, $userpassword) {
global $default_dbname, $user_tablename;


$user_tablename = "Table2";


$link_id = odbc_connect('phpaccess', '', '') or die("Could not connect !");

$query = "SELECT username From Table2 WHERE userid = '$userid' AND userpassword = password('$userpassword')";

$result = odbc_do($link_id, $query);
if(!odbc_num_rows($result)) return 0;
else {
$query_data = odbc_fetch_row($result);
return $query_data[0];
}
}

function login_form() {
global $PHP_SELF;
?>



<html>
<head>
<title>test session login</title>
</head>
<body>
<form method="post" action="<? echo $PHP_SELF ?>">
<div align="center"><center>
login<br>
<table border="1" width="200" cellpadding="2">
<tr>
<th width="18%" align="right" nowrap>id</th>
<td width="82%" nowrap>
<input type="text" name="userid" size="8">
</td>
</tr>
<tr>
<th width="18%" align="right" nowrap>password</th>
<td width="82%" nowrap>
<input type="password" name="userpassword" size="8">
</tr>
<tr>
<td width="100%" colspan=2" align="center" nowrap>
<input type="submit" value="login" name="submit">
</td>
</tr>
</table>
</center></div>
</form>
</body>
</html>




<?
}

session_start();
if(!isset($userid)) {
login_form();
exit;
}
else {
session_register("userid", "userpassword");
$username = auth_user($userid, $userpassword);
if(!username) {
session_unregister("userid");
session_unregister("userpassword");
echo "fail" .
"username/password invalid or not registered" .
"try again <br>\n";

echo "<a href=\"$PHP_SELF\">login</a><br>";
exit;
}

else echo "welcome $username";
}
?>
 
Old October 28th, 2004, 12:39 PM
Registered User
 
Join Date: Oct 2004
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

any help?

 
Old November 19th, 2004, 09:48 AM
Registered User
 
Join Date: Nov 2004
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey
Your first problem is form action

If you are not getting any errors that means your form action is wrong.
get rid of echo from action.

action="<?=$PHP_SELF?>">
second and very basic problem is you are not checking $_POST['submit']...you form method is post so
you have to check if($_POST['submit']){all code}

try it


 
Old November 19th, 2004, 04:34 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Hey there,

About the form action. Either way works fine, so it was fine before.

The second thing... I suggest you use if(isset()) instead of just if() like this:

if(isset($_POST['submit'])) {code}

I also suggest you using up-to-date methods for sessions! session_register and session_unregister are long depreciated. Read the manual for more info.

But, I believe your problem is here: you are not using superglobals. _POST variables and _SESSION variables are superglobals. For example, you seem to be getting the variable $userid from nowhere - use $_POST['userid'] instead, because you are passing values from the first page to the next page with the POST method.

-Snib
Where will you be in 100 years?
Try new FreshView 0.2!




Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 6 Blog - Cannot Login Access DB bmoran007 BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 4 November 26th, 2007 10:53 AM
pass a login name as session variable abhishek0807 ASP.NET 2.0 Professional 1 March 30th, 2007 12:49 AM
User Login - For Session helga@trisyn.co.za ADO.NET 2 September 25th, 2005 12:20 PM
login page and session variables scdownload Classic ASP Basics 0 December 8th, 2003 06:13 PM
login and session sahabat_id2000 Beginning PHP 1 July 9th, 2003 03:24 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.