Another redirect issue (profile page) |
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? ![]() ![]() Mekaboo PHP Code: redirect('Your_Controller_name/function_name'); What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(05-24-2019, 03:30 AM)InsiteFX Wrote: 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?
php.net - mysqli_bind_param
See Also: What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(05-24-2019, 02:20 PM)InsiteFX Wrote: php.net - mysqli_bind_param Thank you so very much for this ![]() |
Welcome Guest, Not a member yet? Register Sign In |