0

Hi,

I have this error:
Notice: Undefined index: menu_name in C:\wamp\www\widget_corp\create_subject.php on line 16

this is the code:

<?php require_once("includes/connection.php")?>
<?php require_once("includes/functions.php")?>
<?php 

//for validation
$required_fields = array('menu_name', 'position', 'visible');
$errors = array(); 

foreach($required_fields as $fieldname){
    if (!isset($_POST[$fieldname]) || empty($_POST[$fieldname])){
    $errors[] = $fieldname;
        }
        
    $fields_with_lengths = array('menu_name' => 30);
    foreach($fields_with_lengths as $fieldname => $maxlength){
        if (strlen(trim(mysql_prep($_POST[$fieldname]))) > $maxlength){
            $errors[] = $fieldname;}
        }    
        if (!empty($errors)){
            redirect_to("new_subject.php");
            }

    }
//end form validation
$manu_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 ( '{$manu_name}', {$position}, {$visible})";
if (mysql_query ($query, $connection)) {
    //seccess
    redirect_to("content.php");

    }else {
        //Display error message.
        echo "<p> Subject createion failed.</p>";
        echo "<p>" . mysql_error() . "</p>";
        }
?>

<?php mysql_close($connection); ?>

this is the line 16

if (strlen(trim(mysql_prep($_POST[$fieldname]))) > $maxlength){

I don't find any problem... do you see anything ?

1
Contributor
1
Reply
2
Views
6 Years
Discussion Span
Last Post by anyname4u
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.