PHP Login Servers

Discussion in 'Scripts, 3rd Party Apps, and Programming' started by toontow7, Oct 1, 2014.

  1. toontow7

    toontow7 New Member

    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    I Created a DataBase, and ik my code works perfectly, since i used xampp to test.
    The code seems fine, it just seems that its not accepting my username and password.

    What format are the PHPmyAdmin Username and Passwords?
    Are they your toontown email and password?

    and i set the server to localhost, which it seems to say.
     
  2. toontow7

    toontow7 New Member

    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    Actually, it works now, but it dosnt seem my PHP server is working.
    The username and password row i created is not working.
    it registers the database, but dosnt register information.
    IK this code works.
     
  3. Dead-i

    Dead-i x10Hosting Support Ninja Community Support

    Messages:
    6,084
    Likes Received:
    364
    Trophy Points:
    83
    Hi toontow7,

    The database details your script is incorrect, as the database user you have specified does not exist. Please create a new database user in cPanel, and then use that one in login.php.

    Thank you,
     
  4. toontow7

    toontow7 New Member

    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    How do you create a new database user in cPanel?
     
  5. AngusThermopyle

    AngusThermopyle Active Member

    Messages:
    319
    Likes Received:
    52
    Trophy Points:
    28
    cPanel regular ...
    Databases section
    MySQLDatabases <----- click on
    Middle of page. "Add New user"
    If your cPanel username is "george" and you add "bush", the full username will be "george_bush"
    Write down the password
    Then, after you have created the user, "Add User To Database" ... add it to your database WITH ALL PRIVILEGES.
     
  6. toontow7

    toontow7 New Member

    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    I created one, but i got this:
    [02-Oct-2014 18:43:04 America/New_York] PHP Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/toontow7/public_html/mysql_login/login.php on line 19
     
  7. AngusThermopyle

    AngusThermopyle Active Member

    Messages:
    319
    Likes Received:
    52
    Trophy Points:
    28
    1) Do not use mysql_xxxxx functions. Use mysqli_xxxxx or PDO. mysql_ is old, deprecated, and soon will not run at all on PHP versions.

    2) You are running mysql_num_rows( $result ) and $result is FALSE --- ie your original query FAILED.

    3) You can always use cPanel --> phpMyAdmin to look into your database and check the actual values in your tables.
     
  8. toontow7

    toontow7 New Member

    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    Well, first when i do mysqli_xxxx, it gives me a bunch of errors, saying i need more parameters.
    Second of all, if i do mysql_xxx, It gives me that one error.
    The query dosnt seem to have anything wrong with it:
    $query = "SELECT * FROM `users` WHERE `Username`='$myusername' and `Password`='$mypassword' ";
    http://gyazo.com/8ed4b2b3adabf5aaeaa824f43526a50c
     
  9. leafypiggy

    leafypiggy Manager of Pens and Office Supplies Staff Member

    Messages:
    3,819
    Likes Received:
    162
    Trophy Points:
    63
    Moved to Scripts and 3rd Party Apps
     
  10. AngusThermopyle

    AngusThermopyle Active Member

    Messages:
    319
    Likes Received:
    52
    Trophy Points:
    28
    Well, your query returns a BOOLEAN -- see the error message you get when you try to use the result in another function.
    It only returns a boolean when you have an ERROR.
    So, something is wrong.
    Every database driver has a function to recover the last error.
    mysql_xxxxx has mysql_error() .
     
  11. toontow7

    toontow7 New Member

    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    So, i still havent solved the problem. I dont know whats wrong....
    dosnt seem like anything's wrong. It works on the my localhost xampp phpmyadmin.
     
  12. AngusThermopyle

    AngusThermopyle Active Member

    Messages:
    319
    Likes Received:
    52
    Trophy Points:
    28
    Did you print out the results of mysql_error() ? Did you?

    Print out $query to make sure it looks right. Print it from the script. Running on x10hosting, not your local machine.

    Try removing the quotes from around users , Username and Password.

    The fact that it runs on your local machine means very little.
     
    • Like Like x 1
  13. toontow7

    toontow7 New Member

    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    I get this when I do die(mysql_error());
    "No database selected"
    same as if I remove the ` ` from the query.

    EDIT

    I added a USE $hostname
    to my query,
    i got this:
    You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SELECT * FROM users WHERE Username='admin' and Password='thunder'' at line 1
     
  14. AngusThermopyle

    AngusThermopyle Active Member

    Messages:
    319
    Likes Received:
    52
    Trophy Points:
    28
    So, the error is before the query ....

    Post all the parts of your script that relate to the mySQL. Otherwise this is just a guessing game.
     
  15. toontow7

    toontow7 New Member

    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    <?php

    $username = "myusername";
    $password = "mypassword";
    $hostname = "localhost";

    $databasehandle = mysql_connect($hostname, $username, $password) or die("Couldn't Connect to the database!");

    $selected = mysql_select_db("login", $databasehandle);

    $myusername = $_POST['user'];
    $mypassword = $_POST['pass'];

    $myusername = stripslashes($myusername);
    $mypassword = stripslashes($mypassword);
    $query = "USE `localhost` SELECT * FROM `users` WHERE `Username`='$myusername' and `Password`='$mypassword'; ";
    $result = mysql_query($query);
    $count = mysql_num_rows($result);

    if($count == 1) {
    $seconds = 300 + time();
    header("location:login_success.php");
    setcookie(loggedin, date("F jS - g:i a"), $seconds);
    } else {
    die(mysql_error());
    }

    mysql_close();

    ?>
     
  16. AngusThermopyle

    AngusThermopyle Active Member

    Messages:
    319
    Likes Received:
    52
    Trophy Points:
    28
    $selected = mysql_select_db("login", $databasehandle);

    The database name would be of the form: yourcPanelUsername_login
    You can test $selected ... FALSE means failure, TRUE means success.
     
  17. toontow7

    toontow7 New Member

    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    Awsome Thanks Man!
    It works perfectly now!
     

Share This Page