Rogue_Phoenix Posted March 12, 2009 Share Posted March 12, 2009 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/>" ; } } Link to comment https://forums.phpfreaks.com/topic/149131-solved-passing-variables-to-mysql-database-using-a-function/ Share on other sites More sharing options...
Maq Posted March 12, 2009 Share Posted March 12, 2009 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. Link to comment https://forums.phpfreaks.com/topic/149131-solved-passing-variables-to-mysql-database-using-a-function/#findComment-783064 Share on other sites More sharing options...
Rogue_Phoenix Posted March 13, 2009 Author Share Posted March 13, 2009 Doh school boy error forgot to place the variable resort_id inside the function so it would recognise it, put it in and away it went and produced it perfectly. Thank you Link to comment https://forums.phpfreaks.com/topic/149131-solved-passing-variables-to-mysql-database-using-a-function/#findComment-783633 Share on other sites More sharing options...
Maq Posted March 13, 2009 Share Posted March 13, 2009 Doh school boy error forgot to place the variable resort_id inside the function so it would recognise it The proper term is variable scope. Link to comment https://forums.phpfreaks.com/topic/149131-solved-passing-variables-to-mysql-database-using-a-function/#findComment-783711 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.