hoopplaya4 Posted November 8, 2008 Share Posted November 8, 2008 I'm pretty new to this, but if someone could perhaps tell me what is wrong with my code, I'd much appreciate it! I'm trying to execute a function, but I get the error: Fatal error: Call to undefined function viewPractice() in /home/content/c/o/a/coachrenke/html/test/secure/practice.php on line 12 Here's my code: <?php session_start(); require("includes/header.php"); require("includes/secureHeader.php"); if ($_POST['submit'] == null){ if ($_SESSION['sessUsrFirstName'] != "") { if($_GET["action"] == "view") { viewPractice(); } // end if if ($_GET["action"] == "") { ?> <h1>Practices </h1> <a href="addPractice.php"><img src="../images/add.gif" border="0" /></a> <a href="addPractice.php">Add a Practice Plan</a><br /><br /> <?php require("../connection.php"); $rs = mysql_db_query($DBname,$sql,$link); //Retrieves data from MySQL $data = mysql_query("SELECT * FROM tblPractices ORDER BY practiceDate LIMIT 10") or die(mysql_error()); //Puts it into an array while($info = mysql_fetch_array( $data )) { //Outputs the list and other data Echo "<a href='practice.php?action=view&num=" . $info['practiceID'] . "'>".$info['practiceDate'] . "</a> <br>"; } ?> <?php function viewPractice() { $sql = "SELECT * FROM tblPractices WHERE (practiceID = " . $_GET["num"] . ")"; require("../connection.php"); $rs = mysql_db_query($DBname,$sql,$link); if ($rs) { while ($row=mysql_fetch_array($rs)){ ?> <div id="communicate"> <form class="uniForm" enctype="multipart/form-data" action="add.php" method="POST"> <table width="80%" cellpadding="0"> <div class="ctrlHolder"> <fieldset> <legend> Practice Date and File </legend> <input id="idhere" name="name" type="text" style="width: 80px;" maxlength="10" /> <div style="float:left" class="col"> <input type="file" class="fileUpload" name="photo" > </div> </fieldset> </div> <div class="ctrlHolder"> <fieldset> <legend>Comments</legend> <TEXTAREA id="styled" ols="115" rows="6" wrap="soft" type="text" name = "email" value="<?= $_GET["practiceComments"] ?>" ></TEXTAREA> </fieldset> </div> <div class="ctrlHolder"> <fieldset> <legend>Private</legend> <TEXTAREA id="styled" wrap="soft" cols="115" rows="6" type="text" name = "phone"></TEXTAREA> </fieldset> </div> <div class="buttonHolder"> <fieldset> <input class="submitButton" type="submit" value="Add Practice"> </fieldset> </div> </table> </form> </div> <?php } //end while } // end if } // End Function editEvent } //end If } } ?> <?php require("../includes/footer.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/131930-solved-_get-issue/ Share on other sites More sharing options...
DeanWhitehouse Posted November 8, 2008 Share Posted November 8, 2008 You haven't got a function called that in the code you showed, unless it is in one of the included files. Quote Link to comment https://forums.phpfreaks.com/topic/131930-solved-_get-issue/#findComment-685394 Share on other sites More sharing options...
hoopplaya4 Posted November 8, 2008 Author Share Posted November 8, 2008 Hi Blade: Thanks for the reply. I thought I had that function on Line 32. <?php function viewPractice() { Is there something else I'm doing wrong? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/131930-solved-_get-issue/#findComment-685408 Share on other sites More sharing options...
nostrodamned Posted November 8, 2008 Share Posted November 8, 2008 Hi your calling the function before its defined - try moving the function up above the line that calls it - I havent looked at the actual function code so not sure if it works. Quote Link to comment https://forums.phpfreaks.com/topic/131930-solved-_get-issue/#findComment-685413 Share on other sites More sharing options...
DeanWhitehouse Posted November 8, 2008 Share Posted November 8, 2008 O'yer, sorry missed that, then the problem is you are calling a function before you have defined it. e.g. test(); function test() { echo "test"; } ^that won't work but function test() { echo "test"; } test(); Will work Quote Link to comment https://forums.phpfreaks.com/topic/131930-solved-_get-issue/#findComment-685414 Share on other sites More sharing options...
PFMaBiSmAd Posted November 8, 2008 Share Posted November 8, 2008 The problem is because the function definition is inside of a conditional statement and it won't be defined until the code in the conditional statement has been executed. Because php is a parsed/tokenized/interpreted language, you can in fact place function definitions anyplace in the code relative to where the function is called, provide the definition is not inside a conditional block of code. Quote Link to comment https://forums.phpfreaks.com/topic/131930-solved-_get-issue/#findComment-685418 Share on other sites More sharing options...
DeanWhitehouse Posted November 8, 2008 Share Posted November 8, 2008 I thought PHP is read top to bottom, meaning the function would need to be defined first? Quote Link to comment https://forums.phpfreaks.com/topic/131930-solved-_get-issue/#findComment-685421 Share on other sites More sharing options...
thebadbad Posted November 8, 2008 Share Posted November 8, 2008 As far as I can remember, in PHP 4 you had to define a function before you ran it, but in PHP 5 the order doesn't matter. Quote Link to comment https://forums.phpfreaks.com/topic/131930-solved-_get-issue/#findComment-685423 Share on other sites More sharing options...
PFMaBiSmAd Posted November 8, 2008 Share Posted November 8, 2008 Because the code is parsed, tokenized, then executed, the function definitions known and any reference to them are fully resolved before the execution phase. Quote Link to comment https://forums.phpfreaks.com/topic/131930-solved-_get-issue/#findComment-685426 Share on other sites More sharing options...
hoopplaya4 Posted November 8, 2008 Author Share Posted November 8, 2008 That was it. Thank you everyone! I learned something new today. I'm appreciative of how helpful everyone is with me learning PHP. Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/131930-solved-_get-issue/#findComment-685433 Share on other sites More sharing options...
hoopplaya4 Posted November 8, 2008 Author Share Posted November 8, 2008 Sorry if I wasn't specific. The issue resolved what that the defined function was still inside the "if" statement. I ended the if statement before the function, and that was it. Quote Link to comment https://forums.phpfreaks.com/topic/131930-solved-_get-issue/#findComment-685434 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.