I am having problem with success messages. If the form is submitted and there are no problems, I want it to alert Success. If the form is submitted and there are problems, I want it to alert Error occurred.
Currently, if I submit something that is posted to MySQL successfully, it gives me no messages. If I submit something that does not meet the requirements within the PHP script it gives me the Success message, not the error message.
JQUERY:
[code]
$(document).ready(function(){
$("#security_add_category").click(function(event){
var category = $("#category").val();
var type_id = $("#type_id").val();
$.ajax({
type: "POST",
url: "../php/security_add_category.php",
data: "category=" + category + "&type_id=" + type_id,
error: function() {
alert('Error occurred.');
},
success: function() {
alert('Success.');
}
});
});
});
[/code]
PHP
[code]
$errors = array();
$category = htmlspecialchars(trim(strtoupper($_POST['category'])));
$type_id = htmlspecialchars(trim($_POST['type_id']));
if (strlen($category) < 3) {
$errors[] = 'Category name must be at least 3 characters';
}
if (strlen($category) > 100) {
$errors[] = 'Category name cannot be more than 100 characters';
}
if (empty($errors)) {
require_once('C:\Extranet\security_add_category.php');
}
[/code]
So for example, if the category name is less than 3 characters, the script does not work, but it gives me the message Success.