Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2006
    Posts
    1,463
    Tokens
    0

    Latest Awards:

    Default [PHP] any errors in this!

    My first piece of PHP
    Thought id see if theirs any errors In it before I uploaded.
    Took a while because I keep getting errors in the PHP Pad I use

    PHP Code:
    <?php session_start(): ?>
    <html>
    <head />
    <body>

    <form action='index.php?login=yes' method=POST>
    Username: <input type=text name='user'><br />
    Password: <input type=password name='pass'><br />
    <input type=submit value='Go!'>
    </form>

    <?php

        $user
    =$_POST['user'];
        
    $pass=$_POST['pass'];
        
    $login=$_GET['login'];
        
        if (
    $login=='yes'){
            
    $con=mysql_connect('192.168.0.4','test',);
            
    mysql_select_db("login");
            
        
    $get=mysql_query("SELECT count(id) FROM login WHERE user='$user' AND pass='$pass");
        
    $results=mysql_result($get0);

        
    mysql_close($con);

        if (
    $result!=1) echo "Login failure!";
        else{
            echo 
    "Login success!";
            
    $_SESSION['user']=$user;
            };
        };
        
    ?>


    </body>
    </html>

  2. #2
    Join Date
    Jul 2005
    Location
    Belgium
    Posts
    2,492
    Tokens
    147

    Latest Awards:

    Default

    Looks alright on the first sight, all I notice is:

    PHP Code:
    pass='$pass" 
    shouldn't that be

    PHP Code:
    pass='$pass'" 
    (forgot the last ' before the " )

    EDIT= that is in this line:
    PHP Code:
     $get=mysql_query("SELECT count(id) FROM login WHERE user='$user' AND pass='$pass");
        
    $results=mysql_result($get0); 

  3. #3
    Join Date
    Apr 2006
    Posts
    1,463
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by [oli] View Post
    Looks alright on the first sight, all I notice is:

    PHP Code:
    pass='$pass" 
    shouldn't that be

    PHP Code:
    pass='$pass'" 
    (forgot the last ' before the " )

    EDIT= that is in this line:
    PHP Code:
     $get=mysql_query("SELECT count(id) FROM login WHERE user='$user' AND pass='$pass");
        
    $results=mysql_result($get0); 
    Yeh thanks Oh well not bad for my first little thing only missed a '

  4. #4
    Join Date
    Nov 2006
    Location
    Cheshire.
    Posts
    730
    Tokens
    250

    Default

    Just quickly edited it all for you!
    PHP Code:
    <?php session_start(); ?>
    <html>
    <head>
    </head>
    <body>

    <form action="index.php?login=yes" method=POST>
    Username: <input type=text name="user"><br />
    Password: <input type=password name="pass"><br />
    <input type=submit value="Go!">
    </form>

    <?php

        $user 
    $_POST["user"];
        
    $pass $_POST["pass"];
        
    $login $_GET["login"];
             
        if (
    $login == "yes")
        {
        
            
    $con mysql_connect("192.168.0.4","test");
            
    mysql_select_db("login");
            
            
    $get mysql_query("SELECT count(id) FROM login WHERE user='" $user "' AND pass='" $pass "'");
            
    $results mysql_result($get0);
            
            
    mysql_close($con);
            
            if (
    $results != 1)
            {
            
                echo 
    "Login failure!";
            
            }
            
            else
            {
            
                echo 
    "Login success!";
                
    $_SESSION["user"]  =$user;
            
            }
        
        }
        
    ?>


    </body>
    </html>
    I think that should work.

    I edited:
    PHP Code:
    <?php session_start(): ?>
    to
    PHP Code:
    <?php session_start(); ?>
    PHP Code:
    $con=mysql_connect('192.168.0.4','test',); 
    to
    PHP Code:
    $con mysql_connect("192.168.0.4""test"); 
    PHP Code:
    $get=mysql_query("SELECT count(id) FROM login WHERE user='$user' AND pass='$pass"); 
    to
    PHP Code:
    $get mysql_query("SELECT count(id) FROM login WHERE user='" $user "' AND pass='" $pass "'"); 
    PHP Code:
    if ($result!=1) echo "Login failure!"
    to
    PHP Code:
            if ($results != 1)
            {
            
                echo 
    "Login failure!";
            
            } 
    I also changed the ''s to ""s , makes me happier.
    Last edited by Frog!; 04-12-2007 at 06:26 PM.


    Give us an add like!

  5. #5
    Join Date
    Apr 2007
    Posts
    2,431
    Tokens
    0

    Latest Awards:

    Default

    Lol at Frog!

    It all looks complicated, so I say you've done it right!

    [X] [X] [X]

  6. #6
    Join Date
    Jan 2007
    Location
    Canada eh?
    Posts
    766
    Tokens
    75

    Default

    I've taken what Frog did and added some room for errors if they are returned, in other words say something fails (like connecting to the database) then it wont just give you a weird error, it will tell you something.

    I've also added a "hidden" field so that if the user just happens to navigate to "index.php?login=yes" unknowingly then it wont try and log them in. Also, you forgot some quotes in your HTML form so I added them

    PHP Code:
    <?php session_start(); ?>
    <html>
    <head>
    </head>
    <body>
     
    <form action="index.php?login=yes" method="post">
    Username: <input type="text" name="user" /><br />
    Password: <input type="password" name="pass" /><br />
    <input type="hidden" name="loginactually" value="yes" />
    <input type="submit" value="Go!" />
    </form>
     
    <?php
     
        $user 
    $_POST["user"];
        
    $pass $_POST["pass"];
        
    $login $_GET["login"];
        
    $submitted $_POST['loginactually'];
     
        if (
    $login == "yes"&&$submitted == "yes")
        {
     
            if(
    mysql_connect("192.168.0.4""test"))
            {
                
    $con mysql_connect("192.168.0.4""test")
                
    $connected "yes";
                if(
    mysql_select_db("login"))
                {
                    
    mysql_select_db("login");
                    
    $selected "yes";
                }else{
                    echo 
    "Could not select database!<br/>";
                    echo 
    "Message from MySQL server: ";
                    echo 
    mysql_error();
                }
            }else{
                echo 
    "Could not connect to MySQL server.";
                echo 
    "Message from MySQL server: ";
                echo 
    mysql_error();
            }
     
            if(
    $connected == "yes"&&$selected == "yes"){
                if(
    $get mysql_query("SELECT count(id) FROM login WHERE user='" $user "' AND pass='" $pass "'"))
                {
                    if(
    $results mysql_result($get0))
                    {
                    }else{
                        echo 
    "Could not get result.<br/>";
                        echo 
    "Message from MySQL server: "
                        
    echo mysql_error();
                    }
                }else{
                    echo 
    "Bad query.<br/>";
                    echo 
    "Message from MySQL server: ";
                    echo 
    mysql_error();
                }
     
            
    mysql_close($con);
     
            if (
    $results != 1)
            {
     
                echo 
    "Login failure!";
     
            }
     
            else
            {
     
                echo 
    "Login success!";
                
    $_SESSION["user"]  = $user;
     
            }
     
        }
     
    ?>
     
     
    </body>
    </html>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •