redirect page after success login

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 6
Joined: Tue Aug 22, 2017 7:11 am

Mon Jul 02, 2018 11:25 pm


I am trying to redirect user to pacific page after giving the right username, password and classgroupid but I am not sure how it is done.

Code: Select all

$query = "SELECT * FROM studentinfo WHERE username = :username AND password = :password AND classgroupid= :classgroupid";  
                $statement = $connect->prepare($query);  
                          'username'     =>     $_POST["username"],  
                          'password'     =>     $_POST["password"],
			  'classgroupid' =>	$_POST["classgroupid"]  
                $count = $statement->rowCount();  
                if($count > 0)  
                     $_SESSION["username"] = $_POST["username"];  
                     header("location: ????.php");  
                     $message = '<label>Wrong Data</label>';  
In the last IF statement is my question, using header to point to location equals to classgroupid, for example, if the classgroupid = test1 then the redirect will be test1.php and so on...

EDIT: I forgot to mention that the record "classgroupid" is also a field in the form itself, so can we take the value from the form if not possible from MySQL database? How it is done?


php-forum Fan User
php-forum Fan User
Posts: 628
Joined: Sat Jun 06, 2015 11:46 am

Wed Jul 04, 2018 10:46 am


If I understand you correctly, you can just concatenate the variable together like this:

Code: Select all

header("location: ". $_POST["classgroupid"] .".php");  

You should really do some validation on the POSTed fields coming from the form though.

Post Reply