Permission tables relationships questions

Off Topic:

You really should use <label> tags with your form inputs; placeholder text is not enough.

Suppose a visitor is in the middle of completing your form, clicks into a field (so the placeholder text is removed) and then the phone rings, or somebody comes to the door. When they return to the form twenty minutes later, how are they to know what information is required in that field? There is no longer anything to tell them. (I speak from experience here; this has happened to me.)

Using labels is also important for accessibility for those using assistive technology.

https://webaim.org/techniques/forms/#labels

1 Like

Thanksā€¦ I will remember to use label tagsā€¦

I got it to workā€¦ I did put some extra spacing with the spacebarā€¦

Hey guys!

I am now having some problems with my code after inserting some additional codes to calculate the costs for a particular service:

<?php
   
   if (!isset($_POST['submit'])) {
      header("Location: ../signup.php");
      exit();
   } else {
   	   include_once 'dbh.php';

   	   $first = mysqli_real_escape_string($conn, $_POST['first']);
   	   $last = mysqli_real_escape_string($conn, $_POST['last']);
   	   $email = mysqli_real_escape_string($conn, $_POST['email']) ;
   	   $uid = mysqli_real_escape_string($conn, $_POST['uid']);
   	   $password = mysqli_real_escape_string($conn, $_POST['pwd']);
   	   $subscriptionplan1 = mysqli_real_escape_string($conn, $_POST['subscriptionplan1']);
      $subscriptionplan2 = mysqli_real_escape_string($conn, $_POST['subscriptionplan2']);
      $subscriptionplan3 = mysqli_real_escape_string($conn,$_POST['subscriptionplan3']);
         $subscriptionplan4 = mysqli_real_escape_string($conn, $_POST['subscriptionplan4']);
   	   $user_activate = mysqli_real_escape_string($conn, $user_activate = 0);
       $overdue = mysqli_real_escape_string($conn, $overdue=0);
       $penalty_amount = mysqli_real_escape_string($conn, $penalty_amount=0);
       $fees = mysqli_real_escape_string($conn, $fees=0);
   	   //Error handlers...

   	   if (empty($first) || empty($last) || empty($email) || empty($uid)|| empty($password)) {
   	   	   header("Location: ../signup.php?signup=empty");
   	   	   exit();
   	   } else {
          //Check if input characters are valid
   	   	    if (!preg_match("/^[a-zA-Z]*$/", $first) || !preg_match("/^[a-zA-Z]*$/", $last)) {
                header("Location: ../signup.php?signup=invalid");
                exit();
   	   	    } else {
   	   	    	
   	   	    	//Checking for valid emails
                 if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
                     header("Location: ../signup.php?signup=email");
                     exit();
                 } else {
                   if (Strlen($password) < 5) {
                   header("Location: ../signup.php?signup=invvalidlength");
                   exit();
                   } else {
                   if(!preg_match('/^(?=.*\d)(?=.*[A-Za-z])[0-9A-Za-z!@#$%]{8,20}$/', $password)) {
                       header ("Location: ../signup.php?signup=notalphanumeric");
                       exit();
                      } else {
                      $sql = "SELECT * FROM users";
                      $result = mysqli_query($conn, $sql);
                      $resultCheck = mysqli_num_rows($result);

                      if($resultCheck > 0) {
                         header("Location: ../signup.php?signup=usertaken");
                         exit();
                      } else {
                      
                      if ($subscriptionplan1 == 'Primer Level' || $subscriptionplan2 == 'Primer Level' || $subscriptionplan3 == 'Primer Level' || $subscriptionplan4 == 'Primer Level') {
                       
                       $fees = 50;


                       } else {
                         if ($subscriptionplan1 == 'Level 1' || $subscriptionplan2 == 'Level 1' || $subscriptionplan3 == 'Level 1' || $subscriptionplan4 == 'Level 1') {

                        $fees = 50;
                       

                       } else {
                        if ($subscriptionplan1 == 'Level 2' || $subscriptionplan2 == 'Level 2' || $subscriptionplan3 == 'Level 2' || $subscriptionplan4 == 'Level 2') {

                        $fees = 50;
                       
                       } else {
                        if ($subscriptionplan1 == 'Level 3' || $subscriptionplan2 == 'Level 3' || $subscriptionplan3 == 'Level 3' || $subscriptionplan4 == 'Level 3') {

                        $fees = 50;
                       
                        } else {

                         // Supply a random generated token for email activation

                      	$token = 'qqewreqreqwsdfdfdafcbvcQERFGHFGHGFHRETERTDF!@#$%^^()';
                      	$token = str_shuffle($token);
                      	$token = substr($token, 0, 10);

                      	//Hashing the password
                      	$hashedPwd = password_hash($password, PASSWORD_DEFAULT);
                      	//Insert the user into the database
                      	$sql ="INSERT INTO users (user_first, user_last, user_email, user_uid, user_password, user_permission, subscriptionplan1, subscriptionplan2, subscriptionplan3, subscriptionplan4, totalfees, paidbydate, overdue, penalty_amount, user_token, user_activate) VALUES ('$first', '$last', '$email', '$uid', '$hashedPwd', '$user_permission', '$subscriptionplan1', '$subscriptionplan2', '$subscriptionplan3', '$subscriptionplan4', '$fees', '20180513 18:45:01','$overdue', '$penalty_amount', '$token', '$user_activate');";

                      	$name = $first .$last;
                        $to = $email;
                        $header = 'From: pianocourse101@hotmail.com';
        
                        $subject = 'Email activation is required';
                         $message = <<<EMAIL

                        Hello $first  $last, 


                        Thanks for registering with PianoCourse101!
                        Please activate your account below before you  
                        can login. Activate your account by clicking   
                        on the following link below....

                         http://localhost/loginsystem/includes/activate.php?email=$to&activatetoken=$token

EMAIL;
       
        
       

                        mail($to, $subject, $message, $header);



                      	mysqli_query($conn, $sql);

                       // insert into permissions table

                      	





                      	header("Location: ../signup.php?signup=success");
                      	exit();
                        }
                 }
   	   	  }
   	   }
   	 }
    



 	     

/*

$subscriptionplan1 = mysqli_real_escape_string($conn, $_POST['
                            subscriptionplan1']);
       $subscriptionplan2 = mysqli_real_escape_string($conn, $_POST['
                            subscriptionplan2']);
       $subscriptionplan3 = mysqli_real_escape_string($conn, $_POST['
                            subscriptionplan3']);
       $subscriptionplan4 = mysqli_real_escape_string($conn, $_POST['
                            subscriptionplan4']);


*/

I have the following error and I guess it has something to do with my {}ā€¦ Are there any tips on how to go about in counting those?

I often just do a search for ( and a search for ) in my code editor. The search results always come back with the numbers of instances it found. If, for example, it found 42 ( and 41 ) I know I have a missing ).

1 Like

How do you do a search for in subline text? I have the following error:

Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\loginsystem\includes\signup2.php on line 155

Iā€™ve never used sublime text, but Ctrl+F genrerally brings up the ā€œfindā€ dialogue.

Logical and ordered Indenting.

1 Like

Thanks but can someone spot a missing brace? I should countā€¦ I guess it is how the {} are grouped in the if else statement that confuses meā€¦

Indent your code properly and Iā€™ll do it straight away.

I might have to do that tomorrow but i think i am missing 4 closing braces

If I highlight one brace (or HTML tag, or whatever) in my code editor, it will highlight the matching one in red. Thatā€™s also helpful, although as @SamA74 says, indenting things properly is the first step. I use Bluefish, but I expect other editors have the same facility.

But does syntax error means that might be a problem with a code and not necessarily the braces? Also, what is the difference between doing it this wayā€¦

if (empty($first) || empty($last) || empty($email) || empty($uid)|| empty($password)) {
   	   	   header("Location: ../signup.php?signup=empty");
   	   	   exit();
   	   } else {
          //Check if input characters are valid
   	   	    if (!preg_match("/^[a-zA-Z]*$/", $first) || !preg_match("/^[a-zA-Z]*$/", $last)) {
                header("Location: ../signup.php?signup=invalid");
                exit();
   	   	    } else {
   	   	    	
   	   	    	//Checking for valid emails
                 if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
                     header("Location: ../signup.php?signup=email");
                     exit();

and just using a basic else if {}?

I did the count thing and it said that there should be 23 open braces but only 21 closed bracesā€¦ I did add some more but now it my signup2 page is blanked and wonā€™t proceed to add into my databaseā€¦

I think I must have put it in the wrong placeā€¦

As soon as an if statement or while loop is opened try copying the if statement and append onto the closing brace:

if (empty($first) || empty($last) || empty($email) || empty($uid)|| empty($password)) {
  // remarks go here

} // if (empty($first) || empty($last) || empty($email) || empty($uid)|| empty($password)) {

Try wrapping the problematic script in /* ā€¦ */ until the script validates.

When you have a clean script without syntax errors gradually decrease the script inside the /* ā€¦ */ until it isolates the problem then rectify.

 if (!isset($_POST['submit'])) {
      header("Location: ../signup.php");
      exit();
   } else {

/* START ISOLATING PROBLEMATIC SCRIPT




   	   include_once 'dbh.php';

   	   $first = mysqli_real_escape_string($conn, $_POST['first']);
   	   $last = mysqli_real_escape_string($conn, $_POST['last']);
   	   $email = mysqli_real_escape_string($conn, $_POST['email']) ;
   	   $uid = mysqli_real_escape_string($conn, $_POST['uid']);
   	   $password = mysqli_real_escape_string($conn, $_POST['pwd']);
   	   $subscriptionplan1 = mysqli_real_escape_string($conn, $_POST['subscriptionplan1']);
      $subscriptionplan2 = mysqli_real_escape_string($conn, $_POST['subscriptionplan2']);
      $subscriptionplan3 = mysqli_real_escape_string($conn,$_POST['subscriptionplan3']);
         $subscriptionplan4 = mysqli_real_escape_string($conn, $_POST['subscriptionplan4']);
   	   $user_activate = mysqli_real_escape_string($conn, $user_activate = 0);
       $overdue = mysqli_real_escape_string($conn, $overdue=0);
       $penalty_amount = mysqli_real_escape_string($conn, $penalty_amount=0);
       $fees = mysqli_real_escape_string($conn, $fees=0);
   	   //Error handlers...

   	   if (empty($first) || empty($last) || empty($email) || empty($uid)|| empty($password)) {
   	   	   header("Location: ../signup.php?signup=empty");
   	   	   exit();
   	   } else {
          //Check if input characters are valid
   	   	    if (!preg_match("/^[a-zA-Z]*$/", $first) || !preg_match("/^[a-zA-Z]*$/", $last)) {
                header("Location: ../signup.php?signup=invalid");
                exit();
   	   	    } else {
   	   	    	
   	   	    	//Checking for valid emails
                 if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
                     header("Location: ../signup.php?signup=email");
                     exit();
                 } else {
                   if (Strlen($password) < 5) {
                   header("Location: ../signup.php?signup=invvalidlength");
                   exit();
                   } else {
                   if(!preg_match('/^(?=.*\d)(?=.*[A-Za-z])[0-9A-Za-z!@#$%]{8,20}$/', $password)) {
                       header ("Location: ../signup.php?signup=notalphanumeric");
                       exit();
                      } else {
                      $sql = "SELECT * FROM users";
                      $result = mysqli_query($conn, $sql);
                      $resultCheck = mysqli_num_rows($result);

                      if($resultCheck > 0) {
                         header("Location: ../signup.php?signup=usertaken");
                         exit();
                      } else {
                      
                      if ($subscriptionplan1 == 'Primer Level' || $subscriptionplan2 == 'Primer Level' || $subscriptionplan3 == 'Primer Level' || $subscriptionplan4 == 'Primer Level') {
                       
                       $fees = 50;


                       } else {
                         if ($subscriptionplan1 == 'Level 1' || $subscriptionplan2 == 'Level 1' || $subscriptionplan3 == 'Level 1' || $subscriptionplan4 == 'Level 1') {

                        $fees = 50;
                       

                       } else {
                        if ($subscriptionplan1 == 'Level 2' || $subscriptionplan2 == 'Level 2' || $subscriptionplan3 == 'Level 2' || $subscriptionplan4 == 'Level 2') {

                        $fees = 50;
                       
                       } else {
                        if ($subscriptionplan1 == 'Level 3' || $subscriptionplan2 == 'Level 3' || $subscriptionplan3 == 'Level 3' || $subscriptionplan4 == 'Level 3') {

                        $fees = 50;
                       
                        } else {

                         // Supply a random generated token for email activation

                      	$token = 'qqewreqreqwsdfdfdafcbvcQERFGHFGHGFHRETERTDF!@#$%^^()';
                      	$token = str_shuffle($token);
                      	$token = substr($token, 0, 10);

                      	//Hashing the password
                      	$hashedPwd = password_hash($password, PASSWORD_DEFAULT);
                      	//Insert the user into the database
                      	$sql ="INSERT INTO users (user_first, user_last, user_email, user_uid, user_password, user_permission, subscriptionplan1, subscriptionplan2, subscriptionplan3, subscriptionplan4, totalfees, paidbydate, overdue, penalty_amount, user_token, user_activate) VALUES ('$first', '$last', '$email', '$uid', '$hashedPwd', '$user_permission', '$subscriptionplan1', '$subscriptionplan2', '$subscriptionplan3', '$subscriptionplan4', '$fees', '20180513 18:45:01','$overdue', '$penalty_amount', '$token', '$user_activate');";

                      	$name = $first .$last;
                        $to = $email;
                        $header = 'From: pianocourse101@hotmail.com';
        
                        $subject = 'Email activation is required';
                         $message = <<<EMAIL

                        Hello $first  $last, 


                        Thanks for registering with PianoCourse101!
                        Please activate your account below before you  
                        can login. Activate your account by clicking   
                        on the following link below....

                         http://localhost/loginsystem/includes/activate.php?email=$to&activatetoken=$token

EMAIL;
       
        
       

                        mail($to, $subject, $message, $header);



                      	mysqli_query($conn, $sql);

                       // insert into permissions table

                      	





                      	header("Location: ../signup.php?signup=success");
                      	exit();
                        }
                 }
   	   	  }
   	   }



FINISH  ISOLATING PROBLEMATIC SCRIPT */
   	 } // if (!isset($_POST['submit'])) {
die;

Braces are part of the code, and form a vital part of the structure of your code.

1 Like

ā€œunexpected end of fileā€ errors are usually caused by braces.
You have already counted in inconsistency in the number of opening to closing ones, so itā€™s a fairly safe bet.

But it seems to me like a lot of time to be spending on a script that will shortly be discarded, only to be re-written with more modern standards.
I have great difficulty finding any reasoning for this. Whatā€™s up with doing it right first time instead of doing what you know to be wrong?

1 Like

I understand that I should do the right thing but i am a newbie and trying to follow the mmtuts tutorialsā€¦ I guess i might have to resort in cutting back on my codes until error freeā€¦

5 posts were split to a new topic: PHP date to MySQL date questions

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.