envexlabs Posted June 22, 2007 Share Posted June 22, 2007 ok, so this is part 2 to my previous post which was solved using global. index.php <?php $store_id = $_GET[store_id]; select_store(); ?> functions.php function select_store(){ global $store_id; $store_info_query = mysql_query('SELECT * FROM `store` WHERE ID = ' . $store_id . ''); global $store_info = mysql_fetch_row($store_info_query); } I can't seem to access any of the $store_info variables in my index.php file. any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/56779-solved-more-include-variable-problems/ Share on other sites More sharing options...
pocobueno1388 Posted June 22, 2007 Share Posted June 22, 2007 Why don't you make the storeID a parameter in your function? <?php function select_store($store_id){ $store_info_query = mysql_query('SELECT * FROM `store` WHERE ID = ' . $store_id . ''); global $store_info = mysql_fetch_row($store_info_query); } ?> Now just use the function like this: <?php select_store($_GET['store_id']); ?> Quote Link to comment https://forums.phpfreaks.com/topic/56779-solved-more-include-variable-problems/#findComment-280426 Share on other sites More sharing options...
cooldude832 Posted June 22, 2007 Share Posted June 22, 2007 using returns <?php function select_store($store_id){ $store_info_query = mysql_query('SELECT * FROM `store` WHERE ID = ' . $store_id . ''); $store_info = mysql_fetch_row($store_info_query); return $store_info; } $store_id = $_GET[store_id]; $store_info = select_store($store_id); ?> Quote Link to comment https://forums.phpfreaks.com/topic/56779-solved-more-include-variable-problems/#findComment-280435 Share on other sites More sharing options...
envexlabs Posted June 22, 2007 Author Share Posted June 22, 2007 my function.php is a seperate file that is included in index.php i think thats where the variable is getting lost. Quote Link to comment https://forums.phpfreaks.com/topic/56779-solved-more-include-variable-problems/#findComment-280445 Share on other sites More sharing options...
cooldude832 Posted June 22, 2007 Share Posted June 22, 2007 try me method it shouldn't matter if its a separate file, plus mine is easy for reusablilty which is the definition of functions Quote Link to comment https://forums.phpfreaks.com/topic/56779-solved-more-include-variable-problems/#findComment-280451 Share on other sites More sharing options...
pocobueno1388 Posted June 22, 2007 Share Posted June 22, 2007 my function.php is a seperate file that is included in index.php i think thats where the variable is getting lost. That shouldn't matter if you are including it in the file your using (which you have to be doing). So thats not the problem. Cooldude832's method should work good for you.... Quote Link to comment https://forums.phpfreaks.com/topic/56779-solved-more-include-variable-problems/#findComment-280452 Share on other sites More sharing options...
envexlabs Posted June 22, 2007 Author Share Posted June 22, 2007 worked like gang busters. i guess i messed something up when i was testing. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/56779-solved-more-include-variable-problems/#findComment-280455 Share on other sites More sharing options...
cooldude832 Posted June 22, 2007 Share Posted June 22, 2007 for added safety use this: using returns <?php function select_store($store_id){ $store_id = mysql_escape_string($store_id) $store_info_query = mysql_query("SELECT * FROM `store` WHERE ID = '$store_id' "); $store_info = mysql_fetch_row($store_info_query); return $store_info; } $store_id = $_GET[store_id]; $store_info = select_store($store_id); ?> Quote Link to comment https://forums.phpfreaks.com/topic/56779-solved-more-include-variable-problems/#findComment-280456 Share on other sites More sharing options...
cooldude832 Posted June 22, 2007 Share Posted June 22, 2007 other wise a person could say || '' and cheat the system Quote Link to comment https://forums.phpfreaks.com/topic/56779-solved-more-include-variable-problems/#findComment-280459 Share on other sites More sharing options...
envexlabs Posted June 22, 2007 Author Share Posted June 22, 2007 so for every mySQL query i execute, should i use mysql_escape_string? Quote Link to comment https://forums.phpfreaks.com/topic/56779-solved-more-include-variable-problems/#findComment-280476 Share on other sites More sharing options...
marcus Posted June 22, 2007 Share Posted June 22, 2007 For ever variable that will be executed in your mySQL queries. Quote Link to comment https://forums.phpfreaks.com/topic/56779-solved-more-include-variable-problems/#findComment-280477 Share on other sites More sharing options...
cooldude832 Posted June 22, 2007 Share Posted June 22, 2007 for your WHERE type logic especially on login scrips beceause a user can say for password || '' and as long as the username was valid they get logged in Quote Link to comment https://forums.phpfreaks.com/topic/56779-solved-more-include-variable-problems/#findComment-280481 Share on other sites More sharing options...
envexlabs Posted June 22, 2007 Author Share Posted June 22, 2007 thanks! Quote Link to comment https://forums.phpfreaks.com/topic/56779-solved-more-include-variable-problems/#findComment-280485 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.