jrm Posted August 4, 2008 Share Posted August 4, 2008 This is my code: CadetNameFunc.php <?php include_once "Connection.php"; if(isset($_GET['CadetID'])) { $CadetID = (int) $_GET['CadetID']; } else { echo 'No Cadet Selected!!'; exit; } CadetName($CadetID); function CadetName($tCadetID) { $CadetInfo = "Select CadetID, Last, First, Middle, Date_Format(DoB,'%d %m %Y') as DoBirth, PhaseID, Right(SSN,4) as Last4 From Cadets_be.Cadets Where CadetID = " . $tCadetID ; $CadetResults = mysql_query($CadetInfo, $link) or die("\n<p> Could not run Query in CadetName() : " . $CadetInfo . " : " . mysql_error()); while($CadetInfo = mysql_fetch_array($CadetResults, MYSQL_ASSOC)) { $CadetName = $CadetInfo["Last"] . ", " . $CadetInfo["First"] . " " . $CadetInfo["Middle"] . "; " . $CadetInfo["Last4"]; $Last4 = $CadetInfo["Last4"]; $DoB = $CadetInfo["DoBirth"]; } } ?> Connection.php (Intranet only) <?php $link = mysql_connect("9.*.*.*:3306","webuser","**********") or die("Could not connect to server: " . mysql_error()); ?> This is my output: Could not run Query in CadetName() : Select CadetID, Last, First, Middle, Date_Format(DoB,'%d %m %Y') as DoBirth, PhaseID, Right(SSN,4) as Last4 From Cadets_be.Cadets Where CadetID = 21 : I get no error code , so I am a bit lost. Can I get some help finding this error? All my other pages work just not this one. Fedora 7 (2.6.23.17-88.fc7) Apache 2.2.8 MySql 5.0.45 Quote Link to comment Share on other sites More sharing options...
jrm Posted August 4, 2008 Author Share Posted August 4, 2008 Ok, just on a whim, I placed the include_once statement inside the function and it worked. Now my question is why? Also how can I reference variables inside of a function? I have this function as well as several others that I would like to use all over my Intranet. I need to reduce the overhead of repititive code over and over in 30 different pages. Would creating different functions for each facet of say "Cadet" (CadetName() as it could be called upto (#ofCadets * 365 * #ofViolations)) be better or keeping it in the individual files? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted August 4, 2008 Share Posted August 4, 2008 The point of functions is the code and data in them are self-contained so that they can be re-used in any code in any file without any need to worry about them inadvertently interacting with the main program code and data. Here are some threads on functions and the data that they use - http://www.phpfreaks.com/forums/index.php/topic,208949.msg949624.html#msg949624 http://www.phpfreaks.com/forums/index.php/topic,206925.msg939695.html#msg939695 Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted August 4, 2008 Share Posted August 4, 2008 As to your first post and title about no errors - when learning php, developing php code, or debugging php code, always turn on full php error reporting to get php to help you. You need to make sure that error_reporting is set to E_ALL and display_errors is set to on. Once your code is working and is error free, then turn display_errors off on a live server to prevent any errors that a hacker will try to trigger from giving him information about your code or your server (but leave error_reporting set to E_ALL so that any problems that are occurring still get logged to your error log file.) Quote Link to comment Share on other sites More sharing options...
jrm Posted August 6, 2008 Author Share Posted August 6, 2008 You are absolutely correct - garbage_out=garbage_in. I have no idea why I did not use this function a long time ago. And I am greatful, because it is actually helping me correct my users on how and what they are putting into the databases. Quote Link to comment 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.