Toy Posted February 18, 2011 Share Posted February 18, 2011 Hey! I'm really stuck on my for fun project... What it's supposed to do is quite obvious, grab an invitation code, check if it's created in the database: If it is it'll let you continue, if not it'll redirect you somewhere else, and it works great but I have two problems. The first problem I have is how to stay on the page if it reloads (like if I get the error "you need to fill out all forms" it'll reload) but when it reloads, the saved invitation code that I grabbed previously will be gone and it'll redirect to someplace, which... I don't want to happen! I tried using sessions to save your code but a user can just open the page several times and it'll create multiple sessions and he can therefore register multiple accounts when only one is meant to be registered or something, I'm kind of confused on this stage. Secondly I want to save the code used to register with in a table but this wont work, IDK why but it just won't. <?php include("connect.php"); $invite = $_GET['code']; $validate_invite = mysql_query("SELECT XX FROM XX WHERE invite = '$invite'"); $rows = mysql_num_rows($validate_invite); if($rows>0) { } else { header('Location: /someplace'); } ?> <?php include("include/header.php"); ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="register"> email <input type="text" name="email"> username <input type="text" name="username"> password <input type="text" name="password"> <input type="submit" name="submit" value="register"> </form> <?php if (isset($_POST['submit']) ) { $email = mysql_real_escape_string($_POST['email']); $username = mysql_real_escape_string($_POST['username']); $password = $_POST['password']; if (!$email || !$username || !$password) { echo 'you need to fill out all forms'; exit (); } $register_query = 'insert into XX (username, password, email, invite) values("'.$username.'", "'.md5($password).'", "'.$email.'", "'.$invite.'"'; mysql_query($register_query); } ?> If someone would care to help me out I would be very happy, I know I explained it kind of complicated and confusing but you get the point, hopefully. I love you phpfreaks:) Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 18, 2011 Share Posted February 18, 2011 Add a column to your invite codes table that is an int (for a timestamp) and called it invite_used. When you register someone, update that invite code with the current timestamp. When you're selecting timestamps that are still valid, you would only select ones with invite_used = 0. Quote Link to comment Share on other sites More sharing options...
Toy Posted February 18, 2011 Author Share Posted February 18, 2011 Oh! I don't have a problem with checking if the codes are valid or not, sorry but I removed bits of unrelevant code what I really need help with is my two problems I explained badly :s Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 18, 2011 Share Posted February 18, 2011 I answered your problem you stated. "I tried using sessions to save your code but a user can just open the page several times and it'll create multiple sessions and he can therefore register multiple accounts when only one is meant to be registered or something, I'm kind of confused on this stage." So...my solution to that is what I explained above. Before you let anyone register with a code, check if it's valid. It doesn't matter what's in the session, what matters is what's in your database. Quote Link to comment Share on other sites More sharing options...
Toy Posted February 19, 2011 Author Share Posted February 19, 2011 I'm really, really confused right now, sorry! I might have written a little unclear or whatever, but what I need help with is: Staying on the page without being redirected to /someplace if I get a validation error "you need to fill out all forms". Submitting the invite code to my database along with the rest of the user information. Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted February 19, 2011 Share Posted February 19, 2011 problem with your insert is that you are missing the cling bracket on your VALUES statement, for the "not redirecting" thing, you will need to increase your validation if() at the top of the page to check for the exact conditions that you want to redirect on. Quote Link to comment Share on other sites More sharing options...
Toy Posted February 19, 2011 Author Share Posted February 19, 2011 If we talk about the "insert" problem I had a close bracket in my real code, I accidently removed it when I deleted other unnecessary code. But it inserts everything else fine (username, password etc.) it's just the invite thing that gets blank after inserting. It seems like after "if (isset($_POST['submit']) ) {" $invite stops working, why is this :S? Quote Link to comment Share on other sites More sharing options...
Toy Posted February 20, 2011 Author Share Posted February 20, 2011 pp Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted February 20, 2011 Share Posted February 20, 2011 Do not bump threads without providing additional, relevant information. Quote Link to comment 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.