Subject: session login with access db
Posted By: surethg Post Date: 10/7/2004 3:41:51 PM
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

<?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";
}
?>


Reply By: surethg Reply Date: 10/28/2004 12:39:55 PM
any help?

Reply By: saper Reply Date: 11/19/2004 8:48:39 AM
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


Reply By: Snib Reply Date: 11/19/2004 3:34:27 PM
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!

Go to topic 22344

Return to index page 711
Return to index page 710
Return to index page 709
Return to index page 708
Return to index page 707
Return to index page 706
Return to index page 705
Return to index page 704
Return to index page 703
Return to index page 702