Jump to content

[SOLVED] passing variables to mysql database using a function


Rogue_Phoenix

Recommended Posts

I wanted to run the following piece of code to query the database and pull out the relevant information when the variable choice was set to a specific choice eg.

<?php prop_size('Studio'); ?>

When i run the code it brings up an error and wont return the information, I know the variable is being passed into the function as it will echo out the variable, what am I missing?

This is my first attempt at functions so I am guessing its going to be something either very simple or very obvious any help on this would be appreciated.

The code in the function is below.


function prop_size($choice) {
$sql = "SELECT prop_id, prop_name FROM properties 
		WHERE resort_id='$resort_id' And prop_active='1' And prop_deleted='0' And category='$choice' ORDER BY prop_name";

$result = mysql_query($sql);

	while ($row = mysql_fetch_array($result))
		{
		$prop_id = $row['prop_id'];
		$prop_name = $row['prop_name'];
		echo "<a href='property.php?propid=$prop_id'>$prop_name</a><br/>" ;
	}
}

When i run the code it brings up an error and wont return the information,

 

What does the error say?

 

resort_id='$resort_id'

 

Where does $resort_id come from?

 

Change this line to:

 

   $result = mysql_query($sql) or die(mysql_error());

 

run the code again and tell me if any errors appear and EXACTLY what they say.

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.