ToonMariner Posted March 15, 2006 Share Posted March 15, 2006 OK If anybody read my post below regarding objects being used in otehr objects.....I THINK i solved my problem there....I had the following....[code]<?php@ $mysqli = new mysqli(DBHOST, DBUSER, DBPASS, DBNAME);if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit();}?>[/code]And wanted to use the $mysqli object in my login check class which was...[code]<?phpclass login_check {function __construct() { // initialize class properties.// ensure no mysql injection in usernamer or password if (isset($_POST['username'], $_POST['password'])) { $this->username = $mysqli->real_escape_string($_POST['username']); $this->password = $mysqli->real_escape_string($_POST['password']); }}....}?>[/code]Now it did not recognize mysqli as an object so here is what I did...I removed the escape string in te constructor and shifted it to the method that queries the database. In the section of my code that executes the login check i did this..[code]<?php$login = new login_check();$login->mysqli = $mysqli;?>[/code]This allowed me to do this to escape the srting...[code]<?php$this->username = $this->mysqli->real_escape_string($_POST['username']);?>[/code]Which works quite nicely.OK The problem is now that the query shoudl return an object (The query string in this example is set but I haven't shown it)...[code]<?php$loginqry = $this->mysqli->query($loginqry);?>[/code]Unfortunately if I try to check the number of rows of the query like so...[code]<?phpif ($loginqry->num_rows == 1) {....}?>[/code]I get the following error....Notice: Trying to get property of non-object in C:\Program Files\Apache Group\Apache2\htdocs\f_m_cms\classes\login.php on line 70line 70 being the if statement..ANy help much appreciated. Link to comment https://forums.phpfreaks.com/topic/5028-oop-help-again/ Share on other sites More sharing options...
trq Posted March 15, 2006 Share Posted March 15, 2006 More than likely your query failed, thereby mysqli-query() would retrun [i]false[/i] and not an object. Try testing it before you try and use it.eg;[code]if ($loginqry) { if ($loginqry->num_rows == 1) { .... }} else { echo "query fialed".$mysqli->error;}[/code] Link to comment https://forums.phpfreaks.com/topic/5028-oop-help-again/#findComment-17791 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.