Jump to content

Hazukiy

Members
  • Posts

    125
  • Joined

  • Last visited

Everything posted by Hazukiy

  1. <?php include ("dbConfig.php"); if ( $_GET["op"] == "reg" ) { $bInputFlag = false; foreach ( $_POST as $field ) { if ($field == "") { $bInputFlag = false; } else { $bInputFlag = true; } } if ($bInputFlag == false) { die( "Problem with your registration info. " ."Please go back and try again."); } $q = "INSERT INTO `TABLENAME` (`name`,`password`,`email`) " ."VALUES ('".$_POST["name"]."', " ."PASSWORD('".$_POST["password"]."'), " ."'".$_POST["email"]."')"; $r = mysql_query($q); if ( !mysql_insert_id() ) { die("Error: User not added to database."); } else { Header("Location: register.php?op=thanks"); } } elseif ( $_GET["op"] == "thanks" ) { echo "<h2>Success!</h2>"; echo "Thank you for registering, you should be able to login now.<br>"; echo "<a href='login.php'>Login</a>"; } else { echo '<form action="?op=reg" method="POST" accept-charset="UTF-8">'; echo 'Username:<br><font color="red">*</font><input class="InputForm" type="text" name="name" id="name"><br>'; echo '<br>'; echo 'Email:<br><font color="red">*</font><input class="InputForm" type="text" name="email" id="email"><br>'; echo '<br>'; echo 'Password:<br><font color="red">*</font><input class="InputForm" type="password" name="password" id="password"><br>'; echo '<br>'; echo '<input type="checkbox" name="tick"><font color="gray" size="3"> I agree to the Terms of Use<br>'; echo '<br>'; echo '<button type="submit" name="submit" class="InputButton" value="Submit">Submit</button>'; echo '</form>'; } ?> Hi, thanks for that login, it works great but now that's changed is there anything in this code that I need to change that they both function with each other because at the moment when I register and try to login it won't let me. Thanks again for the help.
  2. Hi, I recently just created a test site to see what I can produce and everything is working fine apart from the login form. Here's the code I have. <?php session_start(); // dBase file include "dbConfig.php"; if ($_GET["op"] == "fail") { echo "<ul><li><h1 class='FailLoginState'>You need to be logged in to access the members area!</h1></li></ul>"; } if ($_GET["op"] == "login") { if (!$_POST["username"] || !$_POST["password"]) { die("You need to provide a username and password."); } // Create query $q = "SELECT * FROM `TABLENAMEHERE` " ."WHERE `username`='".$_POST["username"]."' " ."AND `password`='".$_POST["password"]."' " ."LIMIT 1"; // Run query $r = mysql_query($q); if ( $obj = @mysql_fetch_object($r) ) { // Login good, create session variables $_SESSION["valid_id"] = $obj->id; $_SESSION["valid_user"] = $_POST["username"]; $_SESSION["valid_time"] = time(); // Redirect to member page Header("Location: members.php"); } else { // Login not successful echo '<form action="?op=login" method="POST">'; echo 'Username:<br><input class="InputForm" type="text" name="username" id="username"><br>'; echo '<br>'; echo 'Password:<br><input class="InputForm" type="password" name="password" id="password"><br>'; echo '<br>'; echo '<button type="submit" name="submit" class="InputButton" value="Login">Submit</button>'; echo '</form>'; echo '<ul><li></li></ul>'; echo("<h1 class='FailLoginState'>Sorry, couldn't log you in. Wrong login information.</h1>"); } } else { echo '<form action="?op=login" method="POST">'; echo 'Username:<br><input class="InputForm" type="text" name="username" id="username"><br>'; echo '<br>'; echo 'Password:<br><input class="InputForm" type="password" name="password" id="password"><br>'; echo '<br>'; echo '<button type="submit" name="submit" class="InputButton" value="Login">Submit</button>'; echo '</form>'; } ?> If they're any bugs or something that looks weird in there it's because I'm new to PHP The problem mainly is when the client trys to log in after registering they can't because when they register it encrypts their password with MD5 encryption so when they go to log in, it comes up with the "Incorrect information" error. How do I make it so that it reads that password from the database? Thanks.
×
×
  • 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.