Can't get the following header to be shown on my browser

I am trying to do some error handlings and I can’t get the following header to be displayed on my browser:

header(“Location: …/signup.php?signup=samesubscriptionerror”);
exit();

It will always show this header instead…

header(“Location: …/signup.php?signup=emptysubscription”);
exit ();


<?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 == '' || $subscription2 == '' || $subscriptionplan3 == '' || $subscriptionplan4 == '') {

                             		header("Location: ../signup.php?signup=emptysubscription");
                             		exit ();
                             	} else {
                               
                               if ($subscriptionplan1 == 'Primer Level' && $subscriptionplan2 == 'Primer Level' && $subscriptionplan3 == 'Primer Level' && $subscriptionplan4 = 'Primer Level') {

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

                             	


                         
                     
                       
       

                         // 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, datejoined, dateofexpiry, overdue, penalty_amount, user_token, user_activate) VALUES ('$first', '$last', '$email', '$uid', '$hashedPwd', '$user_permission', '$subscriptionplan1', '$subscriptionplan2', '$subscriptionplan3', '$subscriptionplan4', '$fees', now(), now() + interval '1' month, '$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();
                        }
                 }
   	   	  }
   	   }
   	 }
   
  }
  
 }   

So your condition does not match.

Also you do an assignment there instead of a comparison.

1 Like

The top part of my code is working but only for these parts:

if ($subscriptionplan1 == 'Primer Level' && $subscriptionplan2 == 'Primer Level' && $subscriptionplan3 == 'Primer Level' && $subscriptionplan4 = 'Primer Level') {

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

I got it… I had the wrong operators… I changed the || to && because if all the fields are empty in my subscription, then don’t run it… got it!

You still have that same error.

1 Like

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