Golbal variable error

I’m working through a tutorial which is building a CMS system. It is using two forms (new_subject.php and create_subject.php) The create_subject.php is picking upthe values by using the global variable $_POST.

[php] $menu_name = $_POST[‘Menu_Name’];
$position = $_post[‘position’];
$visible = $_post[‘visible’];
[/php]

I’m getting and error and do not know what I’m doing wrong. Error is as follow: "Undefined index: Menu_Name in .“path to create_subject.php”. " Looking at the tutorial code it’s exactly the same.

Can somebody please guide me in helping to solve my problem.

What does your form HTML look like? Also, $_post is invalid, it must be $_POST

You get an undefined index, because the $_POST isn’t set, you have to check to see if it is set first

for example

[php]if (isset($_POST[‘visible’])) {
$visible = $_POST[‘visible’]; // Make sure $_POST is CAPITALIZED
}[/php]

Thanks m@tt.
I’ve corrected the typo but still getting the error.
The code for the Form (new_subject.php ) as requested.
[php]

<?php require_once("../_Includes/connection.php"); ?> <?php require_once("../_Includes/functions.php"); ?> <?php find_selected_page();?> <?php include("../_Includes/header.php"); ?>

Add Subject

Subject name:

Position: <?php $subject_set = get_all_subjects(); $subject_count = mysql_num_rows($subject_set); // $subject_count +1 because we are adding a subject for($count=1; $count <= $subject_count+1; $count++){ echo "{$count}"; } ?>

        </select>
    </p>
    <p> Visible:
    	<input type="radio" name="visible" value="0"/>No
        &nbsp;
        <input type="radio" name="visible" value="1"/>Yes
    </p>
    <input type="submit" value="Add Subject" />
</form>
<br/>
<a href="content.php">Cancel</a>    
<?php echo navigation($sel_subject,$sel_page);?>
Content for id "sidebar" Goes Here
<?php require("../_Includes/footer.php"); ?>

[/php]

Thanks Strider64
I’ve checked if the variable (all three are set as well as corrected the typo). What’s confusing to me is that the code on my page corresponds 100% to the code on the tutotial I’m trying to follow and .

I think I know why I’m getting the error and just need confirmation.
Although I’m getting the error when I’m viewing the create_subject.php page on which the variables are used. If I test the New_subject.php page, the data is saved in the database and therefor works correctly. Can I then assume that when I view/ run the create_subject.php page the reason I’m getting the errors is because the $_POST variables are not set with a value (as I’m on the create_subject.hph and not the new_subject.php page). Does that make sense what I’m trying to say?

Your name on the input does not match. Note the case?

<input type="text" name="menu_name" value="" id="menu_name" />

[php]$menu_name = $_POST[‘Menu_Name’];[/php]

It looks like your “$_post” should be like “$_Post”.

Sponsor our Newsletter | Privacy Policy | Terms of Service