Jump to content

[SOLVED] more include variable problems


envexlabs

Recommended Posts

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?

Link to comment
Share on other sites

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']);

?>

 

Link to comment
Share on other sites

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);
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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);
?>

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.