dv90 Posted September 4, 2008 Share Posted September 4, 2008 Im pretty inexperienced with php and mysql but I managed to make a register script. It uses post method to insert 2 fields in, Username and Password. Register Script: <?php $con = mysql_connect("localhost","***","******"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("login", $con); $sql="INSERT INTO users (Username, Password) VALUES ('$_POST[user]','$_POST[pass]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } mysql_close($con) ?> <html> <head> <script type="text/javascript"> <!-- function delayer(){ window.location = "index.html" } //--> </script> </head> <body onLoad="setTimeout('delayer()', 1500)" bgcolor=#333333> <center> <font color=#fff>Registration Successful!</font> </center> </body> </html> But now I need a Login script. I got this far, but i dont think im even close. I need to use $_POST[user] and $_POST[pass] and check if the info is right. Im stuck. Please help. Extra codes: Index with register and login: <html> <body> <b>LOGIN</b> <form action="login.php" method="post"> User:<input type="text" name="user" /> Pass:<input type="text" name="pass" /> <input type="submit" /> </form> <b>REGISTER</b> <form action="reg.php" method="post"> User:<input type="text" name="user" /> Pass:<input type="text" name="pass" /> <input type="submit" /> </form> </body> </html> Login code so far: <?php $con = mysql_connect("localhost","******","********"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("login", $con); $result = mysql_query("SELECT Username FROM users"); echo "<table border='1'> <tr> <th>Username</th> <th>Password</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['Username'] . "</td>"; echo "<td>" . $row['Password'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> Link to comment https://forums.phpfreaks.com/topic/122658-creating-loginredgister-system-from-scratch/ Share on other sites More sharing options...
fenway Posted September 4, 2008 Share Posted September 4, 2008 Why are you display all the login/pass data? The way I do this is to search on username, and then get back the ENCRYPTED password and check. Link to comment https://forums.phpfreaks.com/topic/122658-creating-loginredgister-system-from-scratch/#findComment-633555 Share on other sites More sharing options...
dv90 Posted September 4, 2008 Author Share Posted September 4, 2008 Im not meaning to display the entire list. I was just doing that for test purposes. What i want to do is what your talking about. Can you help? Link to comment https://forums.phpfreaks.com/topic/122658-creating-loginredgister-system-from-scratch/#findComment-634065 Share on other sites More sharing options...
fenway Posted September 5, 2008 Share Posted September 5, 2008 Well, first you have to store the encrypted password, say with SHA1/MD5 -- but in php... then you INSERT into the DB directly, so the plaintext password is never "sent". You simply do the opposite in reverse. Link to comment https://forums.phpfreaks.com/topic/122658-creating-loginredgister-system-from-scratch/#findComment-634526 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.