Jump to content

Please help with this code


headstress
Go to solution Solved by 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");
 
 
}
 
Edited by headstress
Link to comment
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;
}
 
 
Link to comment
Share on other sites

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');
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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