Jump to content

SpartanTacoDuckie

Members
  • Posts

    18
  • Joined

  • Last visited

SpartanTacoDuckie's Achievements

Newbie

Newbie (1/5)

2

Reputation

  1. Okay, thanks to the people who helped. That's solved it for me, and everything is working as it should. I'll be sure to post on this site again if anything happens.
  2. Yes, I have a submit button..: <input type="submit" name="submit" value="Log in"> The error for not having all fields filled in is fine, but correct credentials and all fields shows the same error.
  3. Another problem, though... It outputs the error whenever all the fields haven't been filled in, but it's not outputting the message for a successful username and password... instead, it outputs the error... Is there possibly an error with this code?: if (isset($_POST['submit']) ) { //get the form data $myusername = ($_POST['username']); $mypassword = ($_POST['password']); //check if all fields are filled in if ( (!$myusername == "") || (!$mypassword == "") ) { echo "Please fill in all fields"; exit; } //check the form in database $sql = "SELECT * FROM users WHERE username = '$myusername' AND password = '$mypassword'"; $result = mysql_query($sql); $account = mysql_num_rows($result); //check if user exists if ($account == 1) { $_SESSION["username"] = $myusername; $_SESSION["password"] = $mypassword; $_SESSION["userrecord"] = mysql_fetch_assoc($result); echo "You have been logged in successfully. Please click <a href=account.php>here</a> to continue."; } ??
  4. @KaiSheng Yes, I am using xampp... but it's Lamp, since I'm on a Linux at the moment.
  5. Yeah, I fixed the other problem I had. with the variables. I was just being stupid and tired. Still didn't work, though. I'll try fixing the submit button. Edit 1: I added the name="submit" attribute, but I don't see what's wrong with if (isset($_POST['submit']) ) { .... Mind explaining? Edit 2: It's now outputting the message. Thanks for you people's help. But, what in the above code (^^^) is wrong? It SEEMS fine...
  6. Now it has errors: Notice: Undefined variable: host in /opt/lampp/htdocs/files/Login-register/login.php on like 37 Notice: Undefined variable: user in /opt/lampp/htdocs/files/Login-register/login.php on like 37 Notice: Undefined variable: password in /opt/lampp/htdocs/files/Login-register/login.php on like 37 Notice: Undefined variable: database in /opt/lampp/htdocs/files/Login-register/login.php on like 38 No database selected Now here's what I don't understand about this: Line 37 is: </head> so it's just closing off the heading... what..? Line 38 is blank; absolutely nothing there. So where is it missing the variables at? Edit: I'm off for today... getting late. I'll check back for any responses tomorrow, try them out, and get back on it. By the way, thanks for the help you've provided so far. Very quick to respond, helpful, and also patient. Thanks. ;3
  7. Nope, no error. Just no output of the damn echo....
  8. Config: <?php $user = "root"; $host = "localhost"; $password = ""; $database = "login-register"; ?> Login: <?php session_start(); ?> <html lang="en"> <html> <head> <title>Login page</title> <meta charset="UTF-8"> <link rel="stylesheet" href="./CSSPAGE.css" </head> <body> <h2 style="text-align:center; color:red">Please log in using the form below.</h2> <br /> <br /> <center> <form name="Login" action="login.php" method="post"> <br /> <br /> Username: <input type="text" placeholder="Enter your username" name="username"> <br /> <br /> Password: <input type="password" placeholder="Enter your password" name="password"> <br /> <br /> <input type="submit" value="Log in"> </center> </form> <?php include 'config.php'; mysql_connect($host, $user, $password) or die(mysql_error()); mysql_select_db($database) or die(mysql_error()); if (isset($_POST['submit']) ) { //get the form data $myusername = ($_POST['username']); $mypassword = ($_POST['password']); //check if all fields are filled in if ( (!$myusername == "") || (!$mypassword == "") ) { echo "Please fill in all fields"; exit; } //check the form in database $sql = "SELECT * FROM users WHERE username = '$myusername' AND password = '$mypassword'"; $result = mysql_query($sql); $account = mysql_num_rows($result); //check if user exists if ($account == 1) { $_SESSION["username"] = $myusername; $_SESSION["password"] = $mypassword; $_SESSION["userrecord"] = mysql_fetch_assoc($result); echo "You have been logged in successfully. Please click <a href=account.php>here</a> to continue."; } } ?> </body> </html> >.>
  9. Hmm, still isn't working right. It's not outputting anything.
  10. Yes, my login/register testing environment's database is called login-register. As for removing $usertable = "users"; .... The table in my database which holds the id, username, and password is called "users". Removing it didn't end up making it work. Maybe an error with my query? $sql = "SELECT * FROM usertable WHERE username = '$myusername' AND password = '$mypassword'"; $result = mysql_query($sql); $account = mysql_num_rows($result);
  11. Okay, I'll keep that in mind. Thanks. ;3 By the way, I'm calling this from a config.php file, which says: <?php $user = "root"; $host = "localhost"; $password = ""; $database = "login-register"; $usertable = "users"; ?>
  12. I'm not worried about security on this, really. It's just a test. As for the query, I changed it to what you suggested, with no success. However, my database is phpMyAdmin using XAMPP (LAMP since it's a Linux (at the moment)) so it should work fine, bit it doesn't seem to be.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.