Search Unity

Login system problem

Discussion in 'Multiplayer' started by Milad-Fathi, Apr 4, 2014.

  1. Milad-Fathi

    Milad-Fathi

    Joined:
    Nov 9, 2012
    Posts:
    32
    hi this is my php code:
    PHP:

    <?php

        
    // Send variables for the MySQL database class.
        
    $database mysql_connect('localhost''root''123') or die('Could not connect: ' mysql_error());
        
    mysql_select_db('sproject01') or die('Could not select database');


            
    $username $_GET['username'];
            
    $password $_GET['password'];



        
    $query "select * FROM `users` WHERE username='$username' and password='$password' LIMIT 1";

        
    $result mysql_query($query) or die('Query failed: ' mysql_error());

    and this is error the I get :
    http://i.imgur.com/sdYrEbX.png

    how can i fix this?
     

    Attached Files:

    Last edited: Apr 4, 2014
  2. JamesPro

    JamesPro

    Joined:
    Mar 5, 2012
    Posts:
    509
    Looks like you haven't even included line 20...
     
  3. Milad-Fathi

    Milad-Fathi

    Joined:
    Nov 9, 2012
    Posts:
    32
    PHP:
    <?php
        session_start
    ();

        
    // Send variables for the MySQL database class.
        
    $database mysql_connect('localhost''root''123') or die('Could not connect: ' mysql_error());
        
    mysql_select_db('fpsproject') or die('Could not select database');

        if (isset(
    $_GET['username']) and isset($_GET['password']))
        {
            
    $username $_GET['username'];
            
    $password $_GET['password'];
        }
        else
        {
            echo 
    "It throwed up an error";
        }



        
    $query "select * FROM `users` WHERE username='$username' and password='$password' LIMIT 1";

       
    // mysql_query("SELECT * FROM `users` WHERE username = $_GET['username']")or die('Query failed: ' . mysql_error());

        
    $result mysql_query($query) or die('Query failed: ' mysql_error());

        
    $num_results mysql_num_rows($result);

        for(
    $i 0$i $num_results$i++)
        {
             
    $row mysql_fetch_array($result);
             echo 
    $row['username'] . "\t" $row['password'] . "\n";
        }
    ?>
     
  4. JamesPro

    JamesPro

    Joined:
    Mar 5, 2012
    Posts:
    509
    Try this:

    Code (csharp):
    1.  
    2.  
    3. <?php
    4.     session_start();
    5.  
    6.     // Send variables for the MySQL database class.
    7.     $database = mysql_connect('localhost', 'root', '123') or die('Could not connect: ' . mysql_error());
    8.     mysql_select_db('fpsproject') or die('Could not select database');
    9.  
    10.     if (isset($_GET['username']) and isset($_GET['password']))
    11.     {
    12.         $username = $_GET['username'];
    13.         $password = $_GET['password'];
    14.        
    15.         $query = "select * FROM `users` WHERE username='$username' and password='$password' LIMIT 1";
    16.         $result = mysql_query($query) or die('Query failed: ' . mysql_error());
    17.         $num_results = mysql_num_rows($result);
    18.  
    19.         for($i = 0; $i < $num_results; $i++)
    20.         {
    21.             $row = mysql_fetch_array($result);
    22.             echo $row['username'] . "\t" . $row['password'] . "\n";
    23.         }
    24.     }
    25.     else
    26.     {
    27.         echo "It throwed up an error";
    28.     }  
    29. ?>
    30.  
    31.  
     
  5. Milad-Fathi

    Milad-Fathi

    Joined:
    Nov 9, 2012
    Posts:
    32
    Thank you , But it Doesn't work
     
  6. JamesPro

    JamesPro

    Joined:
    Mar 5, 2012
    Posts:
    509
    Any errors that your getting?
     
  7. Milad-Fathi

    Milad-Fathi

    Joined:
    Nov 9, 2012
    Posts:
    32
    It returns
    It throwed up an error
    and this mean that if statement doesn't work
     
  8. JamesPro

    JamesPro

    Joined:
    Mar 5, 2012
    Posts:
    509
    So another words your not actually setting the username and password so it's going into the else statement.
     
  9. Milad-Fathi

    Milad-Fathi

    Joined:
    Nov 9, 2012
    Posts:
    32
    The problem is that if i change the query to
    insert into usres values (NULL, '$username', '$password');
    there is no error
     
  10. Milad-Fathi

    Milad-Fathi

    Joined:
    Nov 9, 2012
    Posts:
    32
    pls Help Me!
    can anyone introduce me any Login system or what?
     
  11. roka

    roka

    Joined:
    Sep 12, 2010
    Posts:
    598
    Try that

     
  12. Ninja ZX10RR

    Ninja ZX10RR

    Joined:
    Mar 28, 2014
    Posts:
    5
    I know it's a bit late and you might not see this but you may take a look at my own THREAD.
     
  13. nastasache

    nastasache

    Joined:
    Jan 2, 2012
    Posts:
    74
    "It throwed up an error" mean the condition if (isset($_GET['username']) and isset($_GET['password'])) is not passed, db query not executed at all.
    You have to access the script by http with both variables in url, like http://yourwebsite/pathtoscript/login2.php?username=aaaa&password=bbbb. This is $_GET for.