Jump to content

Invitation!


Toy

Recommended Posts

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:)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.