berry05 Posted December 8, 2008 Share Posted December 8, 2008 i googled php form validations and got nothing good..i'm trying to make a php register script that has a username, email, password1, password2...password1 and 2 cant be the same, they both have to be different and people cant register with the same username as somebody else or same email address as somebody else...any help? or any good php validation tuts? thxs! Quote Link to comment https://forums.phpfreaks.com/topic/136124-any-good-form-validations-out-there/ Share on other sites More sharing options...
berry05 Posted December 8, 2008 Author Share Posted December 8, 2008 woops! heres the code <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("register", $con); $sql="INSERT INTO users (username, email, password1, password2) VALUES ('$_POST[username]','$_POST[email]','$_POST[password1]','$_POST[password2]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "Registration Success!!!"; mysql_close($con) ?> Quote Link to comment https://forums.phpfreaks.com/topic/136124-any-good-form-validations-out-there/#findComment-709859 Share on other sites More sharing options...
berry05 Posted December 8, 2008 Author Share Posted December 8, 2008 anyone? Quote Link to comment https://forums.phpfreaks.com/topic/136124-any-good-form-validations-out-there/#findComment-710045 Share on other sites More sharing options...
gevans Posted December 8, 2008 Share Posted December 8, 2008 Hows your php?? Why don't you try writting your own?? Quote Link to comment https://forums.phpfreaks.com/topic/136124-any-good-form-validations-out-there/#findComment-710048 Share on other sites More sharing options...
berry05 Posted December 8, 2008 Author Share Posted December 8, 2008 lol i know but my php is horrible...i tried learning of of w3schools for a little more than a week and im trying to make a text based game and its not working out well because i havent made the registration script yet..i tried tuts and they work good on registration scripts but im trying to make one where you have 2 passwords and they have to be different and you have to enter your email address and you have to make a user name also and i dont know what to do...the code on top is the code i have so far that puts the data submitted into the table.. Quote Link to comment https://forums.phpfreaks.com/topic/136124-any-good-form-validations-out-there/#findComment-710051 Share on other sites More sharing options...
berry05 Posted December 8, 2008 Author Share Posted December 8, 2008 heres the code you wanted... <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("register", $con); $sql="INSERT INTO users (username, email, password1, password2) VALUES ('$_POST[username]','$_POST[email]','$_POST[password1]','$_POST[password2]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "Registration Success!!!"; mysql_close($con) ?> Quote Link to comment https://forums.phpfreaks.com/topic/136124-any-good-form-validations-out-there/#findComment-710058 Share on other sites More sharing options...
DeanWhitehouse Posted December 8, 2008 Share Posted December 8, 2008 Try reading through some of these http://djw-webdesign.awardspace.com/snippet.php?cat=1¤tpage=1 And try http://www.tizag.com/phpT/forms.php Quote Link to comment https://forums.phpfreaks.com/topic/136124-any-good-form-validations-out-there/#findComment-710063 Share on other sites More sharing options...
gevans Posted December 9, 2008 Share Posted December 9, 2008 <?php $con = mysql_connect("localhost","root",""); if (!$con) die('Could not connect: ' . mysql_error()); mysql_select_db("register", $con); $username = (isset($_POST['username'])) ? mysql_real_escape_string($_POST['username']) : FALSE; $email = (isset($_POST['email'])) ? mysql_real_escape_string($_POST['email']) : FALSE; $password1 = (isset($_POST['password1'])) ? md5($_POST['password1']) : FALSE; $password2 = (isset($_POST['password2'])) ? md5($_POST['password2']) : FALSE; if(!$username) die('Username not set'); if(!$email) die('Email not set'); if(!$password1) die('Password1 not set'); if(!$password2) die('Password2 not set'); if($password1 === $password2) die('Password1 and Password2 must be different'); $query = "SELECT username,email FROM users"; $result = mysql_query($query) or die('Error: ' . mysql_error()); while($row = mysql_fetch_assoc($result)){ if($email == $row['email']) die('Email already in use'); if($username == $row['username']) die('Username already in use'); } $sql="INSERT INTO users (username, email, password1, password2) VALUES ('{$username}','{$email','$password1}','{$password2}')"; $result = mysql_query($sql) or die('Error: ' . mysql_error()); echo "Registration Success!!!"; mysql_close($con) ?> Quote Link to comment https://forums.phpfreaks.com/topic/136124-any-good-form-validations-out-there/#findComment-710069 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.