Jump to content

Recommended Posts

I need to alter some code so that it will check that certain requirements are met before registration submission is pressed. I will explain what i need to have checked below the code i have done so far.

 

Here is what i got so far:

 

<?php
if (isset($_POST['RegistrationSubmission'])) {

$Username = $_POST['Username'];
$Password = $_POST['Password'];
$Password2 = $_POST['Password2'];

If ($Password == $Password2) {
    mysql_connect("localhost", "root", "private") or die (mysql_error());
    mysql_select_db("database") or die (mysql_error());
    $query = "INSERT INTO `registrationdetails` (Username) Values ('$Username')";
    echo $query;
    mysql_query($query) or die(mysql_error());
}
else if ($Password != $Password2) {
    echo "passwords did not match";
}
}
?> 

 

 

Basically i need the following added to this code:

 

A)Validate if the check box is checked to agree to the terms of service else give error and reset all fields.

 

B)If the username is taken or not, providing an error and reseting the fields if username is taken.

 

C)Upon a successful registration go to "thisurl" automatically. Is this possible?

 

D)Also just to add, im unsure if this can be done but i want to store the user's IP so they cannot physically access the registration page again, by checking if the IP is registered already...

Link to comment
https://forums.phpfreaks.com/topic/61293-adding-a-few-things-to-my-registration/
Share on other sites

check if checkbox is checked:

if(!$_POST['checkboxname']) { die('You did not agree with terms of service'); }

 

 

check username

 $chkUSR = mysql_query("SELECT * FROM `registrationdetails` WHERE `user` = '".$_POST['Username']."'");
$getUSR = mysql_fetch_object($chkUSR);
if($_POST['Username'] == $getUSR->Username) {
  die('username already registered');
}

 

redirect

header("Location: success.php");

For A I would use Javascript for B I'm not too sure how to approach that...I'll have a think about it and for C you would just use like...

 

header('location: somepage.php');

 

I'm new to all this so if this didn't help then don't complain...there will be someone who knows how to help you.  :)

 

could you kindly explain that last bit:

 

header("Location: success.php");

 

what is success.php exactly? is that where i store the url ?

 

It will just redirect to that url yes.

 

 

If you used Javascript you could make sure that if they clicked Submit they would be informed that they have to tick the checkbox whereas if you user Php it will take you to another page then say they need to go back and click the checkbox...which is...annoying.

 

If you want I can try find you a Javascript code snippet to do what you want?

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.