Jump to content

php form validation problem


azeem123456

Recommended Posts

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

<?php

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);

?>

 

Link to comment
https://forums.phpfreaks.com/topic/193279-php-form-validation-problem/
Share on other sites

As I have said somewhere else, it is really helpful when debugging to try to narrow down the area that is giving you a problem. Once you have found the area then put some echo statements in or var_dump or something to show what is in those variables. This way you can trace through what is happening.

 

Most poeple do not have time to wade through a large program chunk of code and understand what it is doing and then give you the answer. If you made a small test program with the part that is giving you trouble, then we may take the time and trouble to be more helpful. Place yourself in our position and I am sure you will appreciate what I mean.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.