Hi, I have a script with a for loop and an if statement nested in it to check if a user selected a certain country and if so put a corresponding value into a session variable.
The full script is rather long and I can't figure out why this error is happening:
Here is the line where it says there is an unexpected '{' :
if (in_array($_SESSION["country"],$ems[$i]){
and here is the full script:
<?php
// This page will list all of the items
// from the product_list table. Each item will have
// a link to add it to the cart
// This page contains the connection routine for the
// database as well as getting the ID of the cart, etc
$dbServer = "mysql.mygisol.com";
$dbUser = "thanato_admin";
$dbPass = "lifedoor";
$dbName = "thanato_regrowth";
function ConnectToDb($server, $user, $pass, $database)
{
// Connect to the database and return
// true/false depending on whether or
// not a connection could be made.
$s = mysql_connect($server, $user, $pass);
$d = mysql_select_db($database, $s);
if(!$s || !$d)
return false;
else
return true;
}
function GetCartId()
{
// This function will generate an encrypted string and
// will set it as a cookie using set_cookie. This will
// also be used as the cookieId field in the cart table
if(isset($_COOKIE["cartId"]))
{
return $_COOKIE["cartId"];
}
else
{
// There is no cookie set. We will set the cookie
// and return the value of the users session ID
session_start();
setcookie("cartId", session_id(), time() + ((3600 * 24) * 30));
return session_id();
}
}
session_start();
// Get a connection to the database
$cxn = ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);
$_SESSION["country"] = $_POST["selcountry"];
$ems[1]= array("Canada");
$ems[2]= array("");
$ems[3]= array("United Kingdom");
$ems[4]= array("Japan");
$ems[5]= array("China");
$ems[6]= array("Azerbaijan","Bosnia","Croatia","Cyprus","Estonia","France","Ireland","Lithuania","Luxembourg","Northern Ireland","Poland","Scotland","Spain","Yugoslavia");
$ems[7]= array("Armenia","Austria","Belgium","Crete-Greece","Czech Republic","Czechoslovakia","Denmark","Deutschland","Faroe Islands","Finland","Germany","Greece","Hungary","Iceland","Latvia","Liechtenstein","Malta","Netherlands","Norway","Portugal","Russia","Slovenia","Sweden","Switzerland","Ukraine");
$ems[8]= array("Austrailia","Guam","Hong Kong","India","New Zealand","Pakistan","Philippines","Singapore","South Austrailia","Taiwan","Tasmania, Austrailia","Vietnam","West Indies");
$ems[9]= array("French Polynesia","Laos","Malaysia","Thailand");
$ems[10]= array("Israel","Italy","Jordan","Turkey","United Arab Emirates","United Arab Republic");
$ems[11]= array("Bahrain","Kuwait","Oman","Qatar","South Africa","South Korea");
$ems[12]= array("Argentina","Bahamas","Bolivia","Brazil","Chile","Columbia","Costa Rica","Dominican Republic","Grenada West Indies","Guatemala","Jamaica","Peru","Trinidad & Tobago","Uruguay");
for ($i=1; $i<=12; $i++){
//check if value in array
if (in_array($_SESSION["country"],$ems[$i]){
//set timezone value if value is in array
$_SESSION["timezone"]=$i;
}//end if
}//end for loop
if ($_SESSION["country"] != "USA")
{
$pagetitle = "International Product List";
$table = "foreign_prodlist";
}
else
{
$pagetitle = "United States Product List";
$table = "product_list";
}
$result = mysql_query("select * from " . $table . " order by itemId asc");
$_SESSION["table"] = $table;
echo $_SESSION["table"];
echo $_SESSION["country"];
?>
<html>
<font face="verdana" size="3" color="black"><br>
<?php echo $pagetitle; ?>
</font>
<body>
<table>
<tr>
<th><font face="verdana" size="2" color="black">Name</font></th>
<th><font face="verdana" size="2" color="black">Price</font></th>
<th><font face="verdana" size="2" color="black">Description</font></th>
</tr>
<?php
while($row = mysql_fetch_array($result))
{
?>
<tr>
<td width="30%" height="25">
<font face="verdana" size="1" color="black">
<?php echo $row["itemName"]; ?>
</font>
</td>
<td width="10%" height="25">
<font face="verdana" size="1" color="black">
$<?php echo $row["itemPrice"]; ?>
</font>
</td>
<td width="50%" height="25">
<font face="verdana" size="1" color="black">
<?php echo $row["itemDesc"]; ?>
</font>
</td>
<td width="10%" height="25">
<font face="verdana" size="1" color="black">
<a href="cart.php?action=add_item&id=<?php echo $row['itemId']; ?>&qty=1">Add Item</a>
</font>
</td>
</tr>
<tr>
<td width="100%" colspan="4">
<hr size="1" color="red" NOSHADE>
</td>
</tr>
<?php } ?>
<tr>
<td width="100%" colspan="4">
<font face="verdana" size="1" color="black">
<a href="cart.php">Your Shopping Cart >></a>
</font>
</td>
</tr>
</table>
<a href="sessiontest01.php">Test SESSION</a>
</body>
</html>
<?php
$_SESSION['table'] = $table;
?>