PHP and functions.. This works, is it supposed to?

sigmend

[H]ard|Gawd
Joined
Aug 6, 2003
Messages
1,303
So today I was changing some stuff around with my MySQL queries on my website. I was cutting/pasting the queries into my include.php and writing the function calls into the page where I cut them from.

Without thinking I had something like this in my include.php
Notice that I use query(). query() is a function I define later on in the include file

include.php
PHP:
          function Submit_Times($AssetNumber, $Name, $CompleteTime, $db_cnx) {
 	$result = query("INSERT INTO `checkin_time` ( `Asset` , `User` , `TimeToComplete` ) VALUES ('$AssetNumber', '$Name', '$CompleteTime');", $db_cnx);
          	return $result;
          }
include.php
PHP:
 function query($query,$db_cnx) {
  	$result = mysql_query ($query, $db_cnx);
  	if(!$result) {
 		$Message = "Something failed inside of the checkin program.\nInformation is as follows\nFailed with: '" . $query . "'\n" . mysql_error() . "\nWhen running " . $_SERVER['PHP_SELF'] . "\n From user: " . $_SESSION['name'];
 			mail("[email protected]", "Query failure", $Message); 
  			echo "Email report sent to dev<br />";
 		 echo "Error.. <br />MySQL said : <br /><textarea readonly='readonly' cols='120' rows='2'>" . mysql_error() . "</textarea>";
 		 echo "<br />With query: <br /><textarea readonly='readonly' cols='120' rows='2'>" . $query . "</textarea>";
  		die();
  				
  	} else {
  	return $result;
  	}
  }
It works, but is it a good idea to use a function I defined inside of another function?
 
it's not a problem at all. it would only be if there was excessive nested function calling, but this is fine.
 
Back
Top