Jump to content

Please help with this code


headstress

Recommended Posts

HI,  I carried out a tutorial on the net for a login form/registration page

 

I have the form fully working but need it to direct to a certain page depending on users login details

 

This is where I am at and cannot get it to direct to right page

<?php
include 'core/init.php';
 
if (empty($_POST) === false) {
$email = $_POST['email'];
$password = $_POST['password'];
 
if(empty($email) === true || empty($password) === true) {
$errors[] = 'You need to enter a username and password';
} elseif (user_exists($email) === false){
$errors[] = 'This email address does not excist';
} elseif (user_active($email) === false){
$errors[] = 'You have not acivated your account';
} else {
$login = login($email, $password);
if($login === false) {
$errors[] = 'Username or Password Incorrect';
} 
 
 
if (logged_in() === true && user_data('user_type')=== 1){
 
header ("Location: member1.php");
 
}
 
else if (logged_in() === true && user_data('user_type')=== 2){ 
 
header ("Location: member2.php"); 
 
 }
 
else if (logged_in() === true && user_data('user_type')=== 3){
 
header ("Location: member3.php");
 
 
}
 
Link to comment
https://forums.phpfreaks.com/topic/280984-please-help-with-this-code/
Share on other sites

These are the functions

 

 

function user_data($user_id) {
$data = array();
$user_id = (int)$user_id;
 
$func_num_args = func_num_args();
$func_get_args = func_get_args();
 
if ($func_num_args > 1) {
unset ($func_get_args[0]);
 
$fields = '`' . implode(' `, ` ', $func_get_args) . '`';
$data = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `user_id` = $user_id"));
return $data;
}
}
function logged_in(){
return (isset($_SESSION['user_id'])) ? true : false;
}
 
 

It looks like the user_data() function expects a user ID. You're currently passing a string:

user_data('user_type')

Thank  you but I am still trying to grasp this php language

 

This php code is in a file called init.php

 

 

if (logged_in() === true) {
$session_user_id = $_SESSION['user_id'];
$user_data = user_data ($session_user_id, 'email', 'user_type', 'name', 'company', 'telephone', 'password');

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.