I have a simple form where a user adds a type of act. Then saves it.
They can then go back and edit it. When they go back to edit I want the type of act they are editing to show as selected in a drop down in the form.
I use a function to print the drop down box and am trying to send the current variable into the function to check and amend the results. Hope that makes sense!
The problem is that the variable $row[act_type] is NOT being seen inside the function
Anyway, here's how I call the function ($row[act_type] DOES exist):
edit_act_types('<?=$row[act_type]?>');
Then to print the drop down I'm using:
function edit_act_types($actType) {
$mysqli = dbConnect(); // connect with db
$query_actTypes="SELECT * FROM actTypes order by actType";
$result_actTypes = $mysqli->query($query_actTypes);
echo '<select class="form-control" id="type" name="type"><option value="">'.$actType.' Select...</option>';
while($row_actType = $result_actTypes->fetch_array()){
if($actType==$row_actType['actTypes_id']) {
$selected = 'selected="selected"';
}
echo '<option value="'.$row_actType['actTypes_id'].'" '.$selected.'>'.$row_actType['actType'].'</option>';
}
echo '</select>';
};
edit_act_types($row['act_type']);? (Also note the quote symbols unless you've declared it as a constant (which you probably haven't unless you havedefine('act_type', 'value')in your code)).edit_act_types('<?=$row[act_type]?>');function call be simplyedit_act_types($row[act_type]);?