Jump to content

Code works untill it is in a function


joesaddigh

Recommended Posts

Hi,

 

I have some code which works but when I created a function and call this same code it doesn't. The error I get is as follows:

 

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/fhlinux010/l/languageschoolsuk.com/user/htdocs/admin/email.php on line 42

Error retrieving schools

 

The code

function CreateSchoolCheckboxes()
{
	echo '<div style="height:400px;width:400px;font:16px/26px Georgia, Garamond, Serif;overflow:scroll;">';

	$querySchools = "SELECT * FROM school";
	$result = mysql_query($querySchools, $conn)
		or die ("Error retrieving schools ".mysql_error());

	while($row = mysql_fetch_array($result))
	{
		$schoolname = $row['name'];    
		echo '<input type="checkbox" name="school" value="'.$schoolname.'">';
		echo $schoolname . '<br>';
	}							  		  

	echo '</div>';
}

 

Im sure that this is probably something simple but any suggestions would be much appreciated.

 

Thanks,

Joe

Link to comment
https://forums.phpfreaks.com/topic/220809-code-works-untill-it-is-in-a-function/
Share on other sites

Functions have their own private variable scope so that they don't have any unintended interaction with the program where you use the function. Writing larger programs would become impossible if you needed to keep track of all the variables you used in and out of functions.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.