My code doesnt seem to be executing correctly. as i submit on a form the two variables, user and country, are then used to select from the database one of 6 options, all users and all countries, all users and us only, all users and foreign countries, indiv users and all countries, indiv users and us, and indiv users and foreign coutries. It might be a passing variable error, im not sure. I usually code in c++ so my coding may be off.
Here is the area that is troubling me:
$user=$_POST['user'];
$country=$_POST['country'];
function indiv_user()
{
if($country == "us")
{
$select = "SELECT * FROM companies WHERE user_assigned='$user' AND co_country = 'US'";
$export = mysql_query ( $select ) or die ( "" );
}
elseif($country == "foreign")
{
$select = "SELECT * FROM companies WHERE user_assigned='$user' AND co_country != 'US'";
$export = mysql_query ( $select ) or die ( "" );
}
else
{
$select = "SELECT * FROM companies WHERE user_assigned='$user'";
$export = mysql_query ( $select ) or die ( "" );
}
}
function all_user()
{
if($_POST['country']== 'us')
{
$select = "SELECT * FROM companies WHERE co_country = 'US'";
$export = mysql_query ( $select ) or die ( "" );
}
elseif($_POST['country']== 'foreign')
{
$select = "SELECT * FROM companies WHERE co_country != 'US'";
$export = mysql_query ( $select ) or die ( "" );
}
else
{
$select = "SELECT * FROM companies";
$export = mysql_query ( $select ) or die ( "" );
}
}
if($user == "all")
{
all_user();
}
else
{
indiv_user();
}
The code below this calls on the export statement but i am receiving an undefined variable export. Everything else on the page works bc if i get rid of the functs and if statements and just have one select and export statement everything works perfectly.