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 ?

sorry, everything ok :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.