I'm working on creating a form that submits to a database using php. Dreamweaver CS5 is telling me that I have a syntax error at line 75. Here is the code but to point out the exact locations of the issue, look for the following comments.
//Dreamweaver is pointing that is something wrong with the syntax
<?php
$fields = array(
'email',
'gender',
'state',
'district'
);
foreach($fields as $fieldName) {
if(isset($_POST[$fieldName]) and trim($_POST[$fieldName]) !==''){
$fieldName = trim($_POST[$fieldName]);
}else {
$errors[] = "Please enter your". $fieldName ."";
}
}
require_once('./Connections/encourage.php');
$sql = sprintf(
"INSERT INTO some_table(email, gender, state, district) VALUES ('%email', '%gender', '%state', '%district', '%suvery')", //change from % to $ if anything goes wrong
mysql_real_escape_string($_POST['email']),
mysql_real_escape_string($_POST['gender']),
mysql_real_escape_string($_POST['state']),
mysql_real_escape_string($_POST['district']),
mysql_real_escape_string($_POST['survey'])
);
if ($result){
echo '<h1 id="mainhead">Thanks for submitting</hl>
<p>You are now registered</p>';
exit();
}else{
echo '<h1 id="mainhead">System Error</hl>
<p>Your registration could not be completed due to a system error We apologize for any incovience</p>';
echo 'p' . mysql_error(). '<br /><br />Query: ' . $query . '</p>';
exit();
}
mysql_close();
} else { //Dreamweaver is pointing that is something wrong with the syntax
echo '<h1 id="mainhead">Error!</h1>
<p class="error">The following error(s) occurred:<br />';
foreach($errors as $msg) {
echo " - $msg<br/>\n";
}
echo '</p><p>Please try again.</p><p><br/></p>';
}
} //Dreamweaver is pointing that is something wrong with the syntax
?>
Your assistance would be greatly appreciated. Thanks!