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

Link to comment
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.