Simple login but nothing happens...
Usually problematic codes seem to give the programmer a notice of failure, but my problem concerning login is that nothing happens at all, which is strange considering that my code is the same as in the book Beginning PHP5, just changed in the databases to fit my own.
What could be wrong? It would be nice solving this easy problem, since every answer I've seen concerning login is a lot more complicated, and then I wanna understand the easy one first.
Would be nice if someone know the (probably easy) answer.
Best regards,
Ols
<?php
//fulatyper.php
include "commondatabase.inc";
if(!isset($User)){
loginform();
exit;}
else{
session_start();
session_register("user", "pass");
$Name = authentic($_POST['user'], $_POST['pass']);
if(!$Name){
$PHP_SELF = $_SERVER['PHP_SELF'];
session_unregister("user");
session_unregister("pass");
echo "Tillträde nekat. " .
"Du måste ange en giltig användare. " .
"Klicka på följande länk för att försöka igen.<br>\n";
echo "<a href=\"$PHP_SELF\">Login</a><br>";
exit;}
else{
echo "Välkommen, $Name!";}}
function loginform() {
global $PHP_SELF;
?>
<html>
<head>
<title>Login</title>
</head>
<body>
<form method="post" action="<?php echo "$PHP_SELF"; ?>">
<div align="center"><center>
<h3>Logga in!</h3>
<table border="1" width="200" cellpadding="2">
<tr><th width="18%" align="right" nowrap>Id</th>
<td width="82%" nowrap>
<input type="text" name="user" size="8">
</td></tr>
<tr><th width="18%" align="right" nowrap>Lösen</th>
<td width="82%" nowrap>
<input type="password" name="pass" size="8">
</td></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>
<?php }
function authentic($User, $Pass) {
global $DefaultDatabase;
$Database = databaseconnection($DefaultDatabase);
if(!$Database) errormessage(sqlerror());
$Query = "SELECT username FROM CommonPeople
WHERE userid = '$User' AND userpassword = password('$Pass')";
$Result = mysql_query($Query);
if(!mysql_num_rows($Result)){
return 0;
else{
$Data = mysql_fetch_row($Result);
return $Data[0];} }
?>
|