Hello, I got a question about and undefined index. I am trying to understand the error as this is the second time I have run across it while learning php from fixing this site. The last time I just needed to add (!isset(before the $POST[])) althought that isn't working for the error this time. So I really want to understand this error and how to fix / troubleshoot it. Any help is greatly appreciated in advance.
line 14 - Undefined index: UserName
line 14 begins with the if below
<?php
if($_POST['UserName']!="" && $_POST['Password1']!="" && $_POST['Password2']!="" && $_POST['Email']!="" && $_POST['Category'] !="" && $_POST['Name'] !="" && $_POST['Country'] !="" && $_POST['State'] !="" && $_POST['City'] !=""&& $_POST['ZipCode'] !="" && $_POST['Adress'] !="" && $_POST['birth']!="" && $_POST['ss']!="" && $_POST['idnumber']!=""&& $_POST['phone']!="" && $_FILES['ImageFile']['tmp_
name']!=""
&& $_FILES['ActImage']['tmp_n
ame']!="" && $_FILES['RImage']['tmp_nam
e']!=""){
$errorMsg="";
//real username
$replacevalues = array('&','/'," ","?","+","%","$","#","@")
;
$username=str_replace($rep
lacevalues
,"", $_POST['UserName']);
//if username already exists
$result = mysql_query("SELECT user FROM chatmodels WHERE user='$username'");
if (mysql_num_rows($result)>=
1){
$errorMsg.="Username exists, please choose another one!<br>";
} else {
//if dir still exists
@rmdir("../../models/".$us
ername."/"
);
@mkdir("../../models/".$us
ername."/"
);
//if password are correct
if($_POST['Password1']!=$_
POST['Pass
word2']) {
$errorMsg.="Passwords do not match<br>";
} else if(strlen($_POST['Password
1'])<6){
$errorMsg.="Passwords must be at least 6 characters long<br>";
}
//user ID
$dateRegistered=time();
$currentTime=date("YmdHis"
);
$userId=md5("$currentTime"
.$_SERVER[
'REMOTE_AD
DR']);
//calculates some time
$day=$_POST['day'];
if ($day<10){$day="0".$day;}
$currentSeconds=strtotime(
$day." ".$_POST['month']." ".$_POST['year']);
//makes the users folder in models folder
$urlThumbnail="../../model
s/".$_POST
['UserName
']."/thumb
nail.jpg";
$urlIdentityImage="../../m
odels/".$_
POST['User
Name']."/"
.$userId."
.jpg";
$urlRImage="../../models/"
.$_POST['U
serName'].
"/represen
tative.jpg
";
//we copy the thumbail image
if (!@copy($_FILES['ImageFile
']['tmp_na
me'],$urlT
humbnail))
{
$errorMsg.="Thumbnail image file could not be copied, please try again.<br>";
}
//we copy the id image
if (!@copy($_FILES['ActImage'
]['tmp_nam
e'],$urlId
entityImag
e)){
$errorMsg.="ID image file could not be copied, please try again.<br>";
}
//we copy the R image
if (!@copy($_FILES['RImage'][
'tmp_name'
],$urlRIma
ge)){
$errorMsg.="Representative
image file could not be copied, please try again.<br>";
}
}
$db_pass=md5($_POST['Passw
ord1']);
if ($errorMsg==""){
mysql_query("INSERT INTO `chatmodels` ( id , user , password , email , language1 , language2 ,language3,language4, birthDate , braSize , birthSign , weight , weightMeasure , height , heightMeasure , eyeColor , ethnicity , message , position , fantasies , hobby , hairColor , hairLength , pubicHair , tImage , cpm , epercentage ,minimum, category , name , country , state , city , zip , adress , actImage , pMethod , pInfo , dateRegistered , owner , lastLogIn , phone ,fax, idtype , idmonth , idyear , idnumber , birthplace , ssnumber , msn , yahoo , icq , broadcastplace, emailtype, status , lastupdate) VALUES ('$userId','$_POST[UserNam
e]' , '$db_pass', '$_POST[Email]', '$_POST[L1]', '$_POST[L2]', '$_POST[L3]', '$_POST[L4]', '$currentSeconds', '$_POST[BraSize]', '$_POST[BirthSign]', '$_POST[Weight]', '$_POST[weightMeasure]', '$_POST[Height]', '$_POST[heightMeasure]', '$_POST[eyeColor]', '$_POST[Ethnic]', '$_POST[Message]', '$_POST[Position]', '$_POST[Fantasies]', '$_POST[Hobbies]','$_POST[
hairColor]
','$_POST[
hairLength
]','$_POST
[pubicHair
]','Thumbn
ail Image', '295', '30','500','$_POST[Categor
y]', '$_POST[Name]', '$_POST[Country]', '$_POST[State]','$_POST[Ci
ty]', '$_POST[ZipCode]', '$_POST[Adress]', 'IdentityImage', '$_POST[PMethod]', '$_POST[PInfo]','$dateRegi
stered','$
sopusernam
e','$dateR
egistered'
,'$_POST[p
hone]','$_
POST[fax]'
,'$_POST[i
dtype]','$
_POST[idmo
nth]','$_P
OST[idyear
]','$_POST
[idnumber]
','$_POST[
birth]','$
_POST[ss]'
,'$_POST[m
sn]','$_PO
ST[yahoo]'
,'$_POST[i
cq]','$_PO
ST[locatio
n]','$_POS
T[emailtyp
e]','pendi
ng','00')"
);
header ("Location: modelregistered.php");
}
}
else
{
$errorMsg="Please fill all the required fields.";
}
?>
line 283 - Undefined index: day
line 283 below begins with the if statement
<select name="day" id="day">
<?
for($i=01; $i<=31; $i++)
{
echo "<option value='$i'";
if ($_POST['day']==$i){ echo "selected";}
echo">$i</option>";
}
?>
</select>
line 289 - Undefined index: month
line 290 - Undefined index: month
line 291 - Undefined index: month
line 292 - Undefined index: month
line 293 - Undefined index: month
line 294 - Undefined index: month
line 295 - Undefined index: month
line 296 - Undefined index: month
line 297 - Undefined index: month
line 289 starts again with the if statements below and follows consecutively.
<select name="month" id="month">
<option value="January" <? if ($_POST['month']=="January
"){ echo "selected";} else if (!isset($_POST['month'])){
echo "selceted";}?>>January</op
tion>
<option value="February" <? if ($_POST['month']=="Februar
y"){ echo "selected";}?>>February</o
ption>
<option value="March" <? if ($_POST['month']=="March")
{ echo "selected";}?>>June</optio
n>
<option value="July" <? if ($_POST['month']=="July"){
echo "selected";}?>>July</optio
n>
<option value="August" <? if ($_POST['month']=="August"
){ echo "selected";}?>>August</opt
ion>
<option value="September" <? if ($_POST['month']=="Septemb
er"){ echo "selected";}?>>September</
option>
<option value="October" <? if ($_POST['month']=="October
"){ echo "selected";}?>>October</op
tion>
<option value="November" <? if ($_POST['month']=="Novembe
r"){ echo "selected";}?>>November</o
ption>
<option value="December" <? if ($_POST['month']=="Decembe
r"){ echo "selected";}?>>December</o
ption>
</select>
line 304 - Undefined index: year
line 304 begins with the if statement as well.
<select name="year" id="year">
<?
for($i=1980; $i<=date('Y')-17; $i++)
{
echo "<option value='$i'";
if ($_POST['year']==$i){ echo "selected";}
echo ">$i</option>";
}
?>
</select>