Forum Moderators: coopster
// Create an empty array to hold the error messages.
$arrErrors = array();
//Only validate if the Submit button was clicked.
if (!empty($_POST['Submit'])) {
// Each time there's an error, add an error message to the error array
// using the field name as the key.
if (count($arrErrors) == 0) {
// If the error array is empty, there were no errors.
// Insert form processing here.
$host = " ";
$user = " ";
$pass = " ";
$dbname = " ";
$connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>");
mysql_select_db($dbname);
$sql_query = mysql_query("INSERT INTO trip_log(triptype, author) VALUES ('$triptype', '$author')")
or die (mysql_error());
header("Location: /index.php?page=Trip_Log");
} else {
// The error array had something in it. There was an error.
// Start adding error text to an error string.
$strError = '<div class="formerror"><p><img src="/uploads/images/triangle_error.gif" width="16" height="16" hspace="5" alt="">Please check the following and try again/p><ul>';
// Get each error and add it to the error string
// as a list item.
foreach ($arrErrors as $error) {
$strError .= "<li>$error</li>";
}
$strError .= '</ul></div>';
}
}
echo '<style>';
echo 'label {
}';
echo '.formerror {
border: 1px solid red;
background-color : #FFCCCC;
width: auto;
padding: 0px 0;
}';
echo '.errortext {
padding-left: 80px;
font: bold smaller sans-serif;
}';
echo '</style>';
echo '<form method="post" action="',$_SERVER['PHP_SELF'],'?page=Test"';
echo '<input type="hidden" name="triptype" value="ATV" />';
echo '<p';if (!empty($arrErrors['author'])); echo '>';
echo '<label for="Trip Report Author">Trip Report Author/label><br />';
echo '<input name="author" type="text" id="author" size="29" maxlength="50" value="',$_POST['author'],'" />';
if (!empty($arrErrors['author'])) echo '<img src="/uploads/images/triangle_error.gif" width="16" height="16" hspace="5" alt=""><br />';
echo '<input type="submit" name="Submit" value="Submit">';
echo '</form>';
I assume its because you have register_globals OFF?
Before this..
$sql_query = mysql_query("INSERT INTO trip_log(triptype, author) VALUES ('$triptype', '$author')")
or die (mysql_error());
add this..
$triptype = mysql_real_escape_string($_POST['triptype']);
$author = mysql_real_escape_string($_POST['author']);
dc