Jump to content

Recommended Posts

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"); ?>

 

Link to comment
https://forums.phpfreaks.com/topic/131930-solved-_get-issue/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/131930-solved-_get-issue/#findComment-685418
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.