Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
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 July 24th, 2006, 11:22 AM
Ols Ols is offline
Registered User
 
Join Date: Jul 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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];} }

?>
 
Old July 25th, 2006, 07:14 PM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What does the line:

<form method="post" action="<?php echo "$PHP_SELF"; ?>">

Compile to? Can you view source and paste what is written to the client?

Jon Emerson
http://www.jonemerson.net/
 
Old July 29th, 2006, 05:04 AM
Ols Ols is offline
Registered User
 
Join Date: Jul 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Not quite sure it does anything, but it seems to call the page itself. Hope the code helps a bit more.


<html>
    <head>
    <title>Login</title>
    </head>

    <body>
    <form method="post" action="/fulatyper.php">
        <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>





Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple Login Logout Apocolypse2005 PHP Databases 1 September 25th, 2008 01:17 AM
simple Login Nuwang Forum and Wrox.com Feedback 1 June 23rd, 2008 11:36 PM
Simple ASP.NET Membership Provider Login jumpseatnews ASP.NET 2.0 Basics 0 July 16th, 2006 10:53 AM
Simple Java Login Page skchbs Java GUI 0 October 9th, 2003 06:14 PM





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