Jump to content
MakeWebGames

vonpea

Members
  • Posts

    7
  • Joined

  • Last visited

    Never

vonpea's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. Thanks Zed :) That worked perfectly
  2. I now have a new issue. When the page is first visited it automatically creates blank entrys in the database for user,email and pass. Once the page has been visited the code is recognising the blank field user in the database as already there so is telling the page to print the username is already in use. How on earth do i stop the page saving those blank fields when it first loads? Below is the code i am using and thank-you in advance for any help Also a small bug the "you now are registered message" also displays the first time you load the page as well its a little irritating :?   <?php mysql_connect("localhost","******","***********"); mysql_select_db("*************_udata"); $action=$_POST['Submit']; $user=$_POST['user']; $email=$_POST['email']; $pass=$_POST['pass']; //if registering, check fields. if (isset($_POST['user']) && isset($_POST['pass']) && isset($_POST['email']) && isset($_POST['vpass'])) { if((empty($_POST['user'])) || (empty($_POST['pass'])) || (empty($_POST['email'])) || (empty($_POST['vpass']))) { echo ('You must fill out all fields.'); exit; } } // check if username exists in database. $qry = "SELECT user FROM udata WHERE user = '".$_POST['user']."'"; $sqlmembers = mysql_query($qry); $name_check = mysql_fetch_array ($sqlmembers); $name_checkk = mysql_num_rows ($sqlmembers); if ($name_checkk != 0) { die('Sorry, the username: [b]'.$_POST['uname'].'[/b]' . ' is already taken, please pick another one.'); } // check passwords match if ($_POST['passwd'] != $_POST['passwd_again']) { die('Passwords did not match.'); } // check show_email data if ($_POST['show_email'] != 0 & $_POST['show_email'] != 1) { die('Nope'); } /* $a=mysql_query("select * from udata where user='$user'"); $b=mysql_num_rows($a); if ($b > 0) { print "Someone already has that username."; exit; } $a2=mysql_query("select * from udata where email='$email'"); $b2=mysql_num_rows($a2); if ($b2 > 0) { print "Someone already has that email."; exit; }*/ //check if passwords are the same if ($_POST['pass'] != $_POST['vpass']) { print "The passwords do not match."; exit; } //end //insert mysql_query("INSERT INTO udata (user, pass, email) VALUES ('$user','$pass','$email')") or die(mysql_error()); { print "You are now registered."; } ?> <form action="" method="post" name="form2" id="form2"> <table> <tr><td>Username:</td><td><input type=text name=user></td></tr> <tr><td>Email:</td><td><input type=text name=email></td></tr> <tr><td>Pass:</td><td><input type=password name=pass></td></tr> <tr><td>Verify Pass:</td><td><input type=password name=vpass></td></tr> <tr><td colspan=2 align=center><input name="Submit" type="submit" class="submit" value="Register!" /> </td></tr> </table> </form>
  3. Hi thanks for the post but just as i checked back i have found a way that what i want works! I havent tested it fully yet and i still have a few issues on the page like it creates a blank entry in the database when it loads the page. I know its not tidy and very sloppy but on my part its an achievement.   // check if username exists in database. $qry = "SELECT user FROM udata WHERE user = '".$_POST['user']."'"; $sqlmembers = mysql_query($qry); $name_check = mysql_fetch_array ($sqlmembers); $name_checkk = mysql_num_rows ($sqlmembers); if ($name_checkk != 0) { die('Sorry, the username: [b]'.$_POST['uname'].'[/b]' . ' is already taken, please pick another one.'); }
  4. <?php mysql_connect("localhost",*********","***********"); mysql_select_db("*****************"); $action=$_POST['Submit']; $user=$_POST['user']; $email=$_POST['email']; $pass=$_POST['pass']; //if registering, check fields. if (isset($_POST['user']) && isset($_POST['pass']) && isset($_POST['email']) && isset($_POST['vpass'])) { if((empty($_POST['user'])) || (empty($_POST['pass'])) || (empty($_POST['email'])) || (empty($_POST['vpass']))) { echo ('You must fill out all fields.'); exit; } } if($_POST['submit']){ $_POST['user'] = trim($_POST['user']); if($_POST['user'] && strlen($_POST['user']) >= 3){ $query = mysql_query("SELECT * FROM udata WHERE user = '$user'"); if(mysql_num_rows($query)){ echo ('user exists.'); exit; } } } //check if passwords are the same if ($_POST['pass'] != $_POST['vpass']) { print "The passwords do not match."; exit; } //end //insert mysql_query("INSERT INTO udata (user, pass, email) VALUES ('$user','$pass','$email')") or die(mysql_error()); { print "You are now registered. Login."; } ?> <form action="" method="post" name="form2" id="form2"> <table> <tr><td>Username:</td><td><input type=text name=user></td></tr> <tr><td>Email:</td><td><input type=text name=email></td></tr> <tr><td>Pass:</td><td><input type=password name=pass></td></tr> <tr><td>Verify Pass:</td><td><input type=password name=vpass></td></tr> <tr><td colspan=2 align=center><input name="Submit" type="submit" class="submit" value="Register!" /> </td></tr> </table> </form>   Well i had an attempt at is and the code seems to work aparat from the fact it doesnt seem to be able to see if the user already exists in the database. Again i know the database is right because it put information in there but i know i am missing something here. I spoke to a friend who suggested using if exists (select * from udata where user ='$user') but i did some research and cant find any reference to "exists". Could someone at least give me a point in the right direction or a slap round the back of the head for doing something wrong thats stupidly obvious. Many thanks again.
  5. Thank-you so much Zed i didnt think of looking for an argument to ask if the field was empty. Its so simple when i think about it now. Although i still have an error where its doing the checks for existing username and email but i am now at least on the right track to resolving that. I'll have a play around and see if i can work it out (i like to try and figure thing sout first rather than the easy option as i dont learn anything otherwise) If i really cant figure it out i'll post again. Many many thanks Zed for that :)
  6. <?php mysql_connect("localhost","*******","******"); mysql_select_db("*********"); $action=$_POST['Submit']; $user=$_POST['user']; $email=$_POST['email']; $pass=$_POST['pass']; //if registering, check fields. if (!isset($_POST['user']) || !isset($_POST['pass']) || !isset($_POST['email']) || !isset($_POST['vpass'])) { print "You must fill out all fields."; exit; } $a=mysql_query("select * from udata where user='$user'"); $b=mysql_num_rows($a); if ($b > 0) { print "Someone already has that username."; exit; } $a2=mysql_query("select * from udata where email='$email'"); $b2=mysql_num_rows($a2); if ($b2 > 0) { print "Someone already has that email."; exit; } //check if passwords are the same if ($_POST['pass'] != $_POST['vpass']) { print "The passwords do not match."; exit; } //end //insert mysql_query("INSERT INTO udata (user, pass, email) VALUES ('$user','$pass','$email')") or die(mysql_error()); { print "You are now registered. Login."; } ?> <form action="" method="post" name="form2" id="form2"> <table> <tr><td>Username:</td><td><input type=text name=user></td></tr> <tr><td>Email:</td><td><input type=text name=email></td></tr> <tr><td>Pass:</td><td><input type=password name=pass></td></tr> <tr><td>Verify Pass:</td><td><input type=password name=vpass></td></tr> <tr><td colspan=2 align=center><input name="Submit" type="submit" class="submit" value="Register!" /> </td></tr> </table> </form>     Thanks for you reply but i still get the same error. I know its me doing something stupid along the way as i said i am completely new to php. I know about the using of include db_connect.php but havent done it yet as i'll tidy it up later when it actually works! I starred out the database info as i know the database works as when i remove the code trying to stop themregistering with empty fields it saves the information fine. I hope posting the code will able people to see what i am doing wrong and better help me with this. My apologies for being that new at it but trying to convert from C++ to php isnt easy :S Thank-you in advance for any further help you may be able to give me.
  7. After many headaches i have finally got a registeration page to work and enter the said fields into the database i though ah-ha success but i realised soon that i didnt have a few lines of code to stop people leaving fields blank and it entering them into the database.   What i basically want it to do is to tell the user that they must fill in all fields before they can register when they hit the register button and not enter anything into the database unless they are all filled.   So i tried the below (please bear with me on this as i learnt C++ years ago and now trying to work with php)   //if registering, check fields. if ($action) { echo "works?"; } if (!$_POST['user'] || !$_POST['pass'] || !$_POST['email'] || !$_POST['vpass']) { print "You must fill out all fields."; exit; }   Now the echo was the check to see if it was following the code lines but all i get on my register page is the print line of the code. If i take those lines out the form shows as normal and i have the original problem of empty fields being entered into the database.   Is there another way to do this or is it simply i am being stupid and putting this in the wrong place in my code.   Thanks in advance for any assistance you may give me.   (If i get any other problems along my journey into php i'll post in this same thread so it saves on spam on the forums as i hate spam)
×
×
  • Create New...