CodeIgniter Forums
Another redirect issue (profile page) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Another redirect issue (profile page) (/showthread.php?tid=73701)



Another redirect issue (profile page) - Mekaboo - 05-23-2019

Howdy!

I obtained codes from 2 sites  for a profile page also redirect controller and tweaked them for what I wanted. Here is the code for both:

profile.php
<?php
// We need to use sessions, so you should always start sessions using the below code.
session_start();
// If the user is not logged in redirect to the login page...
if (!isset($_SESSION['loggedin'])) {
    redirect(base_url("redirect_controller/v2"));
    exit();
}
$DATABASE_HOST = '50.87.144.41';
$DATABASE_USER = 'cultured_root';
$DATABASE_PASS = 'brownie81';
$DATABASE_NAME = 'cultured_codeignite';
$con = mysqli_connect($DATABASE_HOST, $DATABASE_USER, $DATABASE_PASS, $DATABASE_NAME);
if (mysqli_connect_errno()) {
    die ('Failed to connect to MySQL: ' . mysqli_connect_error());
}
// We don't have the password or email info stored in sessions so instead we can get the results from the database.
$stmt = $con->prepare('SELECT password, email FROM accounts WHERE id = ?');
// In this case we can use the account ID to get the account info.
$stmt->bind_param('s', $_SESSION['id']);
$stmt->execute();
$stmt->bind_result($password, $email);
$stmt->fetch();
$stmt->close();
?>

redirect_controller.php
<?php
   class Redirect_controller extends CI_Controller {
    
      public function index() {
        
      }
      
      public function v2() {
         /*Load the URL helper*/
         $this->load->helper('url');
   
         /*Redirect the user to some internal controller’s method*/
         redirect('profile');
      }
        
   }
?>

I changed the original header in profile page and made it a redirect but get a 404 error. My goal is to connect profile page to DB so when folks login the page would be specifically for that person. FYI after one logs in they're directed to a dashboard, all of this works fine. From the dashboard want connect with profile page(think social network or a forum like this one). How do I connect and redirect?

Heart Heart ,
Mekaboo


RE: Another redirect issue (profile page) - InsiteFX - 05-24-2019

PHP Code:
redirect('Your_Controller_name/function_name'); 



RE: Another redirect issue (profile page) - Mekaboo - 05-24-2019

(05-24-2019, 03:30 AM)InsiteFX Wrote:
PHP Code:
redirect('Your_Controller_name/function_name'); 

This works perfectly but now I got this error within the php:

An uncaught Exception was encountered

Type: Error
Message: Call to a member function bind_param() on boolean
Filename: /home4/cultured/public_html/application/views/profile.php
Line Number: 13
Backtrace:
File: /home4/cultured/public_html/application/controllers/Login.php
Line: 47
Function: view
File: /home4/cultured/public_html/index.php
Line: 315
Function: require_once 

Its because of this code:
// We don't have the password or email info stored in sessions so instead we can get the results from the database.
$stmt = $con->prepare('SELECT password, email FROM accounts WHERE id = ?');
// In this case we can use the account ID to get the account info.
$stmt->bind_param('s', $_SESSION['name']);
$stmt->execute();
$stmt->bind_result($password, $email);
$stmt->fetch();
$stmt->close();

The main issue is highlighted. Trying to figure out how to change this, can you help with this?


RE: Another redirect issue (profile page) - InsiteFX - 05-24-2019

php.net - mysqli_bind_param

See Also:


RE: Another redirect issue (profile page) - Mekaboo - 05-24-2019

(05-24-2019, 02:20 PM)InsiteFX Wrote: php.net - mysqli_bind_param

See Also:

Thank you so very much for this Heart