Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (array_key_exists("newuser", $_POST))
- {
- registerNewUser($_POST["username"], $_POST["password"]);
- }
- else
- {
- loginUser($_POST["username"], $_POST["password"]);
- }
- function registerNewUser($user, $pass)
- {
- global $conn;
- $cmd = "SELECT * FROM `simpleuser` WHERE `username` = '$user'";
- $result = $conn->prepare($cmd);
- $result->execute();
- if ($result->rowCount() > 0)
- {
- displayMessage("That username already exists.");
- }
- else
- {
- $cmd = "INSERT INTO `simpleuser` VALUES ('$user', '$pass')";
- echo $cmd."<br />";
- $result = $conn->prepare($cmd);
- $result->execute();
- displayMessage("User successfully added.");
- }
- }
- function loginUser($user, $pass)
- {
- global $conn;
- $cmd = "SELECT `password` FROM `simpleuser` WHERE `username` = '$user'";
- $result = $conn->prepare($cmd);
- $result->execute();
- if ($result->rowCount() == 0)
- {
- displayMessage("Username or password is incorrect");
- }
- else
- {
- $data = $result->fetch();
- if ($data["password"] == $pass)
- {
- displayMessage("Welcome back, $user!");
- }
- else
- {
- displayMessage("Username or password is incorrect");
- }
- }
- }
- function displayMessage($msg)
- {
- echo "$msg<br/>";
- echo "<a href = 'index.php' >Go Home</a>";
- }
- ?>
- <html>
- <head>
- <title></title>
- <style>
- input
- {
- margin: 10px 10px;
- }
- </style>
- <script>
- function initialize()
- {
- }
- </script>
- </head>
- <body onload = "initialize();">
- <form method = "post" action = "register.php">
- Username: <input type = "text" name = "username"/>
- Password: <input type = "text" name = "password"/>
- New User? <input type = "checkbox" name = "newuser" />
- <input type = "submit" value = "Login"/>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement