I rewrited the code.... and now it works... see if you can spot the difference between this and the first code i submitted...
PHP Code:
if (isset($_POST["submit"])){
$errors_array = array();
$required_fields = array("menu_name", "position", "visible");
foreach($required_fields as $fieldname){
if(empty($_POST[$fieldname]) || $_POST[$fieldname] == "" ){
$errors_array[] = $fieldname;
}
}
//field length
$fields_with_lengths = array("menu_name" => 30);
$errors_array = check_max_field_lengths($fields_with_lengths);
if(empty($errors_array)){
//form validation
//perform update
$id = mysql_prep($_GET["subj"]);
$menu_name = mysql_prep($_POST["menu_name"]);
$position = mysql_prep($_POST["position"]);
$visible = mysql_prep($_POST["visible"]);
$query = "UPDATE subjects SET
menu_name = '{$menu_name}',
position = '{$position}',
visible = '{$visible}'
WHERE id = {$id}";
$result = mysql_query($query, $connection);
if(mysql_affected_rows() == 1){ //mysql query test
//success
$message = "The subject was successfully updated";
}else{
//errors
$message = "The subject update failed.";
$message .= "<br />" . mysql_error();
}
}else{
//errors
if(count($errors) == 1){
$message = "there was an error in the submitted form";
}else{
$message = "There were " . count($errors_array) . " errors in the form";
}
}
}
And here is a simple version of the code....
PHP Code:
<?php
if (isset($_POST["submit"])){
$errors_array = array();
$required_fields = array("username");
foreach($required_fields as $fieldname){
if(empty($_POST[$fieldname]) || $_POST[$fieldname] == "" ){
$errors_array[] = $fieldname;
}
}
if(empty($errors_array)){ //no error
//form validation
echo "OK";
}else{
//error
echo "ERROR";
}
}
?>
<!--fun.php is the _self -->
<form name="input" action="fun.php" method="POST">
Username: <input type="text" name="username" />
<input name="submit" type="submit" value="Submit" />
</form>
Bookmarks