shane0714 Posted July 1, 2007 Share Posted July 1, 2007 I have been working on something that should be simple but I cannot figure out how to do it. Basically, I am working with a PHP class that handles MySQL queries. The code to call a query looks like looks like: $dbcn->db_qry("DELETE FROM contactus WHERE id='$id'","1"); This function is inside a class called db_connect. The function is function db_qry($qry, $type, $from="") { $this->dbQryResult = mysql_query($qry) or $this->goError($qry, mysql_error(), $type, $from); } As the function shows, if the query fails, it is directed to the goError() function where it prints an error message. The problem is that some instances, I want it to instead return a variable back out of the function. The variable holds some information so I can print out the error message later in the page. In this case, it should return a variable indicating whether the query succeeded. That variable will be used in the following part: if ($dbcn->db_qry != false) { $status = '<div id="statussuccess">Your selected message(s) have been successfully deleted.</div>'; } else { $status = '<div id="statusfailure">There was a problem deleting the selected messages.</div>'; } I'm stumped here. I've tried a number of things, but I think the closest I've gotten is to change the db_qry() function to: function db_qry($qry, $type, $from="") { if($type != 1) { $this->dbQryResult = mysql_query($qry) or $this->goError($qry, mysql_error(), $type, $from); } else { $this->dbQryResult = mysql_query($qry); return $this->dbQryResult; } } I know this is probably something simple, but so far I haven't figured it out. Link to comment https://forums.phpfreaks.com/topic/57999-solved-return-a-variable-from-class-function/ Share on other sites More sharing options...
teng84 Posted July 1, 2007 Share Posted July 1, 2007 or $this->goError($qry, mysql_error(), $type, $from); remove that if you dont want to be redirected Link to comment https://forums.phpfreaks.com/topic/57999-solved-return-a-variable-from-class-function/#findComment-287465 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.