I am getting an error from a foreach statement, not sure why, here is the code:
PHP Code:
$new_prod_id = $count + 100;
function arrayQuery($f_prod_id,$table)
{
$sql=mysql_query("SELECT * FROM $table WHERE prod_id='$f_prod_id'");
if(mysql_num_rows($sql))
{
return(mysql_fetch_assoc($sql)); // use fetch_assoc
}
return false;
}
function createSpec($f_desc,$f_step_num,$f_prod_id) {
$sql=mysql_query("INSERT INTO specs (descriptor,num,prod_id) VALUES ('$f_desc','$f_step_num','$f_prod_id')") or die (mysql_error());
}
$spec=arrayQuery($type,"specs");
$i=0
foreach($spec['descriptor'] as $descriptor) {
createSpec($spec['descriptor'],[$i],$new_prod_id);
$i++;
}
"descriptor" is a column in the specs DB.
I am trying to write 27 rows in the specs database from a template created. I get the values using "$spec=arrayQuery($type,"specs");" and then I want to loop for each array value and create a new row in the specs DB.
This is the error I am getting:"Parse error: syntax error, unexpected T_FOREACH in"
Any help would be greatly appreciated.
Bookmarks