i m stucked in form validation i am trying to make content management system so which i have 2 subjects products services without form validation when i add new subject my code work i want to validate the form like what if user send long string as an menu name or what if user didn't enter the name but the send the position of new subject so i want to validate these things so i wrote these code it compiles correct and doesn't give me error when i add some subject it doesn't respond anything it doesn't add anything i write data on menu name select position number then click on Yes radio button to make it visible and hit submit button it doesn't do anything not add any thing or doesn't redirect back to content.php it doesnt work help me out please include("includes/connection.php"); include("includes/functions.php"); // form validation $errors=array(); $required_feilds=array('menu_name','postion','visible'); foreach($required_feilds as $feildname){ if(!isset($_POST[$feildname])|| empty($_POST[$feildname])){ $errors[]=$feildname; } } $feild_with_lengths=array('menu_name'=>30); foreach($feild_with_lenghts as $feildname=>$maxlenght){ if(strlen(trim(mysql_prep($_POST[$feildname])))>$maxlenght){ $errors[]=$feildname;} } if(!empty($errors)){ redirect("new_subject.php"); } //$_POST = array_map('mysql_real_escape_string', $_POST); $menu_name= mysql_prep($_POST['menu_name']); $position = mysql_prep($_POST['position']); $visible = mysql_prep($_POST['visible']); $query = "INSERT INTO subjects ( menu_name, position, visible) Values ( '{$menu_name}',{$position},{$visible})"; if(mysql_query($query,$connection)){ header("Location:content.php"); exit; }else { echo "<p> Subject creation is failed .</p>"; echo "<p>".mysql_error()."</p>"; } mysql_close($connection); PHP:
thanks for all the suggestion the problem is solved error was in the array $required_feilds=array('menu_name','postion','visible'); i wrote wrong spelling postion it should position nw it works fine thanks alot for every one