Notice: Undefined index: (already defined)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

Notice: Undefined index: (already defined)

Post by ghadacr »

I'm getting this error, and i have already defined the variable, need help cant seem to find where the problem is....

Error:
Notice: Undefined index: canceldate

Notice: Undefined index: RoomAssociationID

Notice: Undefined variable: newcancel

Code: Select all

<?PHP include 'header.php'; ?>

<?PHP include "opendb.php";

extract($_POST);

//$MaxPax = $_POST['MaxPax'];
$roomtype = $_POST['roomtype'];
$subcat = $_POST['subcat'];
$dummy_room = $_POST['dummy_room'];
$roomnumbers = $_POST['roomnumbers'];
$notes = $_POST['notes'];
//$dummyname = $_POST['dummyname'];
$roomtype = $_POST['roomtype'];
//$typeinter = $_POST['typeinter'];
$datefrm = $_POST['datefrm'];
$dateto = $_POST['dateto'];
$canceldate = $_POST['canceldate'];
$notes = $_POST['notes'];
$RoomAssociationID = $_POST['RoomAssociationID'];

$daterep = str_replace("/","-",$datefrm);
$datereps = str_replace("/","-",$dateto);
$csds = str_replace("/","-",$canceldate);

$newdate = date ("d M Y", strtotime ($daterep)); 
$newdates = date ("d M Y", strtotime ($datereps)); 


$Notes = str_replace("'","''","$notes");
$typeinters = str_replace("'","''",'typeinter');
$RoomType = str_replace("'","''","$roomtype");
$dummynames = str_replace("'","''",'dummyname');

if($canceldate == null) {
$newcancel == null;

} else {

$newcancel = date ("d M Y", strtotime ($csds));  
}
function check_field2($roomnumbers)
{
  if(!preg_match("/[^0-9\ ]+$/",$roomnumbers))
    return TRUE;
  else
    return FALSE;
}




$status = "OK"; // setting the flag for form validation
$msg=""; // error message string is blank


// Now let us check if name is entered or not
if(strlen($subcat) < 1 ){ // if name is less than two char length
$msg .="<center>Please select a hotel</center><BR>";
$status="NOT OK";
}

// Now let us check if name is entered or not
if(strlen($roomtype) < 1 ){ // if name is less than two char length
$msg .="<center>Please enter a room type</center><BR>";
$status="NOT OK";
}

if($datefrm>=$dateto){ // if name is less than two char length
$msg .="<center>Please enter a <font color=FF0000>date to</font> that is greater than date from </center><BR>";
$status="NOT OK";
}

// Now let us check if name is entered or not
if(strlen($roomnumbers) < 1 ){ // if name is less than two char length
$msg .="<center>Please enter the amount of rooms</center><BR>";
$status="NOT OK";
}

// Now let us check if name is entered or not

  if(!check_field2($roomnumbers))
{
  
$msg .="<center>Please enter a number for room amounts</center><BR>";
$status="NOT OK";
}


if($status<>"OK"){ // if form validation is not passed
echo "<BR><BR>";
echo $msg. "<br><center><input type='button' value='Retry' onClick='history.go(-1)'></center><br><br><br>";

}else{


//$query ="INSERT INTO HotelRooms (HotelID, DummyRoom, RoomNumbers, DummyCancellationDate, AvailableFrom, AvailableTo, DummyName, RoomType, Notes, MaxPax) VALUES ('$_POST[subcat]','$_POST[dummy_room]','$_POST[roomnumbers]','$newcancel','$newdate','$newdates','$dummynames','$RoomType','$Notes','$_POST[MaxPax]')";

$query = mssql_init ("sp_insertHotelRooms"); 

if($RoomAssociationID = null) {

mssql_bind($query, "@HotelID", $subcat, SQLFLT8); 

mssql_bind($query, "@DummyRoom", $dummy_room, SQLBIT);

mssql_bind($query, "@RoomNumbers", $roomnumbers, SQLVARCHAR);

mssql_bind($query, "@DummyCancellationDate", $newcancel, SQLVARCHAR);

mssql_bind($query, "@AvailableFrom", $newdate,SQLVARCHAR);

mssql_bind($query, "@AvailableTo", $newdates, SQLVARCHAR);

mssql_bind($query, "@DummyName", $dummynames, SQLVARCHAR);

mssql_bind($query, "@RoomType", $RoomType, SQLVARCHAR);

mssql_bind($query, "@Notes", $Notes, SQLVARCHAR);

mssql_bind($query, "@MaxPax", $MaxPax, SQLVARCHAR);

mssql_bind($query, "RETVAL", &$HotelRoomID, SQLINT2);

mssql_execute($query);

//

} else (

$i = 0;


while ($i != $roomnumbers) {
    //echo "Value: $i<br />\n";


//$result = mssql_query($query);
	




++$i;

}
if ($query) 
echo"Inserted new room<BR>$HotelRoomID<br>$canceldate<bR><input type='button' value='Back' onClick='history.go(-1)'>";

else echo"<p>Problem inserting user!!!!";
}

$query2 = mssql_init ("sp_InsertAssociatedRooms"); 


mssql_bind($query2, "@HotelRoomID", $HotelRoomID, SQLINT2); 

mssql_bind($query2, "@HotelRoomID2", $RoomAssociationID, SQLINT2);

mssql_execute($query2);

mssql_close();
?>
<?PHP include 'footer.php'; ?>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

$_POST contains the posted parameters of the request the script is handling.
If the client/browser did not send a post parameter canceldate with this request there will be no $_POST['canceldate'] => notice: Undefined index.
see http://de3.php.net/isset
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Undefined indexes are not the same as undefined variables. Please look at what volka posted as the undefined index relates to the post array member.

Also note that any time you blindly assign a value from an unknown data source, you run the risk of undefined index errors. An easy and clean way to avoid said errors is to use the isset() or empty() function as a conditonal check.
Post Reply