Jump to content

[SOLVED] UNDEFINED INDEX


june_c21

Recommended Posts

hi, i'm stuck in this error

 

code :

<?php

session_start();

$host = 'localhost';

$user = 'root';

$password = 'admin';

$dbase = 'staff';

 

$dblink = mysql_connect($host,$user,$password);

mysql_select_db($dbase,$dblink);

 

$staff_no    = $_POST['staff_no'];

$position  = $_POST['position'];

$date    = $_POST['date'];

$app_letter = $_POST['app_letter'];

$info_form    = $_POST['info_form'];

$handbook    = $_POST['handbook'];

$access_card    = $_POST['access_card'];

$vehicle_sticker  = $_POST['vehicle_sticker'];

$medical_check_up  = $_POST['medical_check_up'];

$safety_briefing  = $_POST['safety_briefing'];

$safety_helmet    = $_POST['safety_helmet'];

$safety_google = $_POST['safety_google'];

$safety_boot  = $_POST['safety_boot'];

$computer    = $_POST['computer'];

$tel_ext    = $_POST['tel_ext'];

$room_no    = $_POST['room_no'];

$email    = $_POST['email'];

$stationary    = $_POST['stationary'];

$uniform    = $_POST['uniform'];

$tshirt    = $_POST['tshirt'];

$medical_card  = $_POST['medical_card'];

$induction_program  = $_POST['induction_program'];

 

 

$query= "INSERT INTO details(staff_no,position,date,app_letter,info_form,handbook,access_card,vehicle_sticker,medical_check_up,safety_briefing,safety_helmet,safety_google,safety_boot,computer,tel_ext,room_no,email,stationary,uniform,tshirt,medical_card,induction_program) VALUES ('$staff_no', '$position','$date','$app_letter','$info_form','$handbook','$access_card','$vehicle_sticker','$medical_check_up','$safety_briefing','$safety_helmet','$safety_google','$safety_boot','$computer','$tel_ext','$room_no','$email','$stationary','$uniform','$tshirt','$medical_card','$induction_program') ";

$result = mysql_query($query,$dblink);

?>

 

error :

Notice: Undefined index: access_card in C:\Web\staff\add.php on line 17

 

Notice: Undefined index: medical_check_up in C:\Web\staff\add.php on line 19

 

Notice: Undefined index: safety_briefing in C:\Web\staff\add.php on line 20

 

Notice: Undefined index: safety_google in C:\Web\staff\add.php on line 22

 

Notice: Undefined index: tel_ext in C:\Web\staff\add.php on line 25

 

Notice: Undefined index: uniform in C:\Web\staff\add.php on line 29

 

Notice: Undefined index: tshirt in C:\Web\staff\add.php on line 30

 

Link to comment
Share on other sites

Before you go and set a bunch of post variables like this. You need to make sure that each POST variable is set

or else the variable you set for it....ie.....$date = $_POST['date']

will fail to be set

$staff_no          = $_POST['staff_no'];
$position         = $_POST['position'];
$date             = $_POST['date'];
$app_letter       = $_POST['app_letter'];
$info_form          = $_POST['info_form'];
$handbook          = $_POST['handbook'];
$access_card       = $_POST['access_card'];
$vehicle_sticker      = $_POST['vehicle_sticker'];
$medical_check_up   = $_POST['medical_check_up'];
$safety_briefing      = $_POST['safety_briefing'];
$safety_helmet       = $_POST['safety_helmet'];
$safety_google        = $_POST['safety_google'];
$safety_boot         = $_POST['safety_boot'];
$computer          = $_POST['computer'];
$tel_ext          = $_POST['tel_ext'];
$room_no          = $_POST['room_no'];
$email             = $_POST['email'];
$stationary          = $_POST['stationary'];
$uniform          = $_POST['uniform'];
$tshirt             = $_POST['tshirt'];
$medical_card      = $_POST['medical_card'];
$induction_program  = $_POST['induction_program'];

to do this....use isset()

 

an easy way to do these is

extract($_POST, EXTR_IF_EXISTS);

but it isn't the best of practice to use it all the time. just something to use real fast if you ever need it

 

 

Link to comment
Share on other sites

nevermind....I misread the error

 

 

undefined index

 

access_card

medical_check_up

safety_briefing

safety_google

tel_ext

uniform

tshirt

 

the form you have..

doesn't contain fields with these names anywhere

e.g

 

medical_check_up might be medicalcheckup on your form page

 

go back and check all your names and make sure they match

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.