I am having a lot of trouble with a variable scoping issue. PHP and OOP is definitely not my strong suit but I'm trying to get this code working:
if (!empty($_POST["username"])){ $connectdb=$_POST["username"]; }else{ $connectdb=$_GET["username"]; }
class Main extends CI_Controller { function __construct() { parent::__construct(); global $connectdb; $this->load->database($connectdb); $this->load->helper('url'); $this->load->library('grocery_CRUD'); }
The idea is to get a user name from a previous login screen and set it to the variable $connectdb. The variable doesn't stay through multiple instances of the constructor. Can someone help!