Danny620 Posted March 10, 2010 Share Posted March 10, 2010 <?php class Northplanet_CMS { var $host = 'localhost'; var $username = 'root'; var $password = '*****'; var $table = '*****'; function connect() { $conn = mysqli_connect($this->host, $this->username, $this->password, $this->table) or die("Could not connect. " . mysql_error()); return $conn; } function update($element_id, $conn) { if(is_numeric($element_id)){ //query to db $q = "SELECT * FROM page_elements WHERE element_id = $element_id"; $r = mysqli_query($conn, $q); echo $r[text]; }else{ $error = 'Invalid Element'; return $error; } } } $Northplanet = new Northplanet_CMS(); $Northplanet->connect(); $update = $Northplanet->update('1',$conn); echo $update; ?> i get an Warning: mysqli_query() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\class.php on line 24 Link to comment https://forums.phpfreaks.com/topic/194800-help-error/ Share on other sites More sharing options...
wildteen88 Posted March 10, 2010 Share Posted March 10, 2010 You need capture the return value of your connect function when you call it. $conn = $Northplanet->connect(); Remember return does not return the actual variable, it only returns the value of the variable. Link to comment https://forums.phpfreaks.com/topic/194800-help-error/#findComment-1024337 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.