Click here to Skip to main content
15,887,338 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Requirements:

Create a PHP application to allow a user to register for the website and enter profile information to be stored in cookies.
Part I: Registration page
Create a page called register.php that displays a user registration form with the following fields from the customer table:
Email address - required, valid email, maxlength 60
First Name - required, maxlength 40
Last Name - required, maxlength 20
Password - required, 8-20 characters
Confirm Password - required, 8-20 characters, must match Password
Read the records from the genre table and display each one as a checkbox using the name as the label and the genreId as the value. Instruct the user to select up to 3 favorite genres. User must select at least 1 genre and no more than 3.
Add a submit button with a value of Register.
When the form is submitted, validate the information and display error messages if there are any errors.
Part II: Create cookies
If the data from the form is all valid, then create cookies as follows:
name: first and last names from the form with a space in between, expires: 30 days from current date
genre1: the first genre selected by the user, expires: 1 year from current date
genre2: the second genre selected by the user, expires: 1 year from current date. If no selection was made, do not create cookie.
genre3: the third genre selected by the user, expires: 1 year from current date. If no selection was made, do not create cookie.
coupon: value = .25, temporary cookie.
Transfer to the index.html page (see next step)
Part III: Index page
Create a page called index.php
Add your header and footer functions for the html
After the header, check to see if the name cookie exists. If so, display the message: Welcome, name! where name is replaced with the value of the name cookie.
Check to see if the coupon cookie exists. If so, display the message: 'Order today to receive 25% off your entire order!".
Check to see if the genre1 cookie exists. If so, get the value and check for the genre2 and genre3 cookies and get those values also if they exist. Create a query to select a maximum of 20 tracks from the tracks table that have a genre that matches one of the genre's entered by the user. (i.e. Select * from tracks where genreId = 1 or genreId = 2 or genreId = 3 limit 20).
If no genre1 cookie exists, just create a simple query to select the first 20 tracks (select * from tracks limit 20)
Execute the sql query.
On the page, display a heading: "Tracks you may like"
List the Name, genreId, composer and unit price for the 20 tracks in your dataset. If the currency is anything other than US Dollars, multiply by the conversion factor from the array and display in the preferred currency.
Include a link to the register.php page.

What I have tried:

PHP
<?php
$conn = mysqli_connect("localhost", "root", "","chinook");
        if (isset($_POST['submit'])) {
        $valid = true;
if (isset($_POST['submit'])) {
$valid = true;

		$email = htmlspecialchars($_POST['email']);
        if (empty($email)) {
            echo "<p class="error">Please enter your email address</p>";
            $valid = false;
}}
		setcookie('email',$email,time()+60*60*7);
	
		if (!preg_match('/[-\w.]+@([A-z0-9][-A-z0-9]+\.)+[A-z]{2,4}/',$email)) {
            echo "<p class="error">Invalid email address</p>";
        }
        $firstname = htmlspecialchars(trim($_POST['firstname']));
        if (empty($firstname)) {
            echo "<p class="error">Please enter your first name</p>";
            $valid = false;
        }
        $lastname = htmlspecialchars(trim($_POST['lastname']));
        if (empty($lastname)) {
            echo "<p class="error">Please enter your last name</p>";
            $valid = false;
        }
       
        $username = htmlspecialchars(trim($_POST['username']));
        if (empty($username)) {
            echo "<p class="error">Please enter a username</p>";
            $valid = false;
        }
	
        $password = htmlspecialchars(trim($_POST['password']));
        if (empty($password)) {
            echo "<p class="error">Please enter a password</p>";
            $valid = false;
        }
		  if (!preg_match('/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\s).{8,15}$/',$password)) {
            echo "<p class="error">Password must have 1 uppercase letter, 1 lowercase letter, 1 number and be 8-15 characters in length</p>";
        }
		if (strlen($password)<8 or strlen($password)>20) {
            echo "<p class="error">password must be between 6 and 12 characters in length</p>";
            $valid = false;
        }
		$confirmpassword = htmlspecialchars(trim($_POST['confirmpassword']));
        if (empty($confirmpassword)) {
            echo "<p class="error">Please enter a confirm password</p>";
            $valid = false;
        }
       
        if (strcmp($password,$confirmpassword)!=0) {
            echo "<p class="error">Passwords do not match</p>";
            $valid = false;
        }
		if (isset($_POST['Genre'])) {
        $playlists = $_POST['Genre'];
        } 
		else {
            echo "<p class="error">Please choose Genre.</p>";
            $valid = false;
            $Genre[0]="";
        }
		if (isset($_POST['register'])) {
            setcookie('firstname', $_POST['firstname'], time()+ (60 * 60 * 24 * 30), "/");
            setcookie('lastname',($_POST['lastname']), time()+ (60 * 60 * 24 * 30), "/");
        
			setcookie('Genre1', md5($_POST['Genre1']), time()+(60*60*24*365),"/");
			setcookie('Genre2', md5($_POST['Genre2']), time()+(60*60*24*365),"/");
			setcookie('Genre3', md5($_POST['Genre3']), time()+(60*60*24*365),"/");
			
			//setcookie('coupon', .25($_POST['coupon']), time()+ "/");
        } else {
            setcookie('firstname', $_POST['firstname'], false, '/');
            setcookie('lastname', md5($_POST['lastname']), false, '/');
        }
        if ($valid) {
            header("Location: index1.php?firstname=$firstname&lastname=$lastname");
            exit();
        }
		
    } else {
        $firstname="";
        $lastname="";
        $email="";
        $username="";
        $password="";
        $confirmpassword="";
		$Genre="";
    }
?>

 <p>
    Email address:
    
</p>
<p>
    First name:
    
</p>
<p>
    Last name:
    
</p>

<p>
    Username:
    
</p>
<p>
    Password:
    
</p>
<p>
	Confirm Password:
    
</p>
<p>
	Genre:
<?php
$conn = mysqli_connect("localhost", "root", "",'chinook');
$query = "Select name from Genre";
$result = mysqli_query($conn,$query);
if (!$result) {
die(mysqli_error($conn)); }
while ($row = mysqli_fetch_assoc($result)){
echo "".$row['name'];
}
?>

</p><p>
    
</p>
Posted
Updated 3-May-18 19:45pm
v2
Comments
OriginalGriff 4-May-18 1:44am    
And?
What does it do that you didn't expect, or not do that you did?
Where are you stuck?
What help do you need?

Use the "Improve question" widget to edit your question and provide better information.
Member 13810736 4-May-18 12:40pm    
I have to make 2 pages: 1-register.php and 2-index.php
according to what I tried, I have form and validation about it in php in register page and now I need

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900