Conjurer Posted March 7, 2011 Share Posted March 7, 2011 I am a bit rusty with mySQL and I tried to borrow some other query code and modify it into an update command...apparently I am trying to use an invalid property in my error checking. Basically I just want to check and see if there were NO rows updated so I can let the user no that nothing was changed. There are probably easier ways to do this? The page where I set the variable values is based on a form post. I am not sure how to write my validation tests. Right now it is running the update successfully but it is reporting back an error based on hitting the "else if" test where I am trying to see if no rows were updated. The error message is: Encountered error: 8 in /home/omgma/public_html/member_community/mbr_profiles/mbr_profile_updt_post.php, line 85: Trying to get property of non-object No fields were updated! Error: 0 //create a SQL statement $updt_cmd = "UPDATE users t1, directory t2 " ."SET t1.email = '$email', " ."t2.first_name='$first_name', " ."t2.last_name='$last_name', " ."t2.suffix='$suffix', " ."t2.website_url='$website_url' " ."WHERE t1.username ='$username' AND t2.directory_id = t1.directory_id"; $conn = db_connect(); $result = $conn->query($updt_cmd); if (!$result) {//could not execute query throw new Exception('<h2>Could not execute member profile update!</h2><p>Error: ' .mysqli_errno($conn) .mysqli_error($conn) .'</p>' ); } else if ($result->num_rows==0) {// no rows so nothing was updated. throw new Exception('<h2>No fields were updated! </h2><p>Error: ' .mysqli_errno($conn) .mysqli_error($conn) .'</p>' ); } else { $mbr_profile = $result->fetch_object(); print_r($mbr_profile); return $mbr_profile; } Am I using the right functions here to do this and if so where can I find the class properties to use to test if nothing was updated? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/229825-where-do-i-find-the-class-objects-that-can-be-used-with-an-update-command/ Share on other sites More sharing options...
trq Posted March 7, 2011 Share Posted March 7, 2011 Am I using the right functions here to do this and if so where can I find the class properties to use to test if nothing was updated? db_connect() is not a native php function, where have you defined it? Quote Link to comment https://forums.phpfreaks.com/topic/229825-where-do-i-find-the-class-objects-that-can-be-used-with-an-update-command/#findComment-1183823 Share on other sites More sharing options...
Conjurer Posted March 7, 2011 Author Share Posted March 7, 2011 Sorry, I had db_connect defined in an include file: function db_connect() { $conn = new mysqli("localhost", "xyz_xyzuser", "x213", "xyz_members"); if (mysqli_connect_errno() > 0) { $errmsg = "Failure - Could not connect to database with db_connect.<br />mysqli_connect_error message: ".mysqli_connect_error()."<br /><br />"; throw (new Exception($errmsg)); } else { //echo "Connection worked! <br>"; return $conn; } } Quote Link to comment https://forums.phpfreaks.com/topic/229825-where-do-i-find-the-class-objects-that-can-be-used-with-an-update-command/#findComment-1183858 Share on other sites More sharing options...
trq Posted March 7, 2011 Share Posted March 7, 2011 where can I find the class properties to use to test if nothing was updated You'll want to look at the mysqli manual. http://php.net/mysqli Quote Link to comment https://forums.phpfreaks.com/topic/229825-where-do-i-find-the-class-objects-that-can-be-used-with-an-update-command/#findComment-1183862 Share on other sites More sharing options...
Conjurer Posted March 7, 2011 Author Share Posted March 7, 2011 Thanks, that helped me sort it. Quote Link to comment https://forums.phpfreaks.com/topic/229825-where-do-i-find-the-class-objects-that-can-be-used-with-an-update-command/#findComment-1183864 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.