Hi,
I have the following code, but for somereason it doesn't work. Can anyone see why?
db_query is a simple mysql_query conection that just connects to the db with out having to use mysql_select_db. I know it works, as I have other scripts with it in.
This script is either meant to add or update records based on $sRoomcode. If ALL is selected it pulls multiple values from another table, then inserts ot updates.
For somereason it doesn't add to the database, but it thinks fo, as it returns the feed back, successfully added/updated.
//all vars present?
if ($sUserID && $sRoomcode && $status && $sday && $smonth && $syear && $eday && $emonth && $eyear) {
mail('availability@hkihotels.com',"$sHotel Availability","AVSTAT|ARSALL|HRSHK|CTYLHR|GMT$time|ATYA|ACT$status|$sPidcont|STD$sday$smonth$syear|EDT$eday$emonth$eyear|RTY$sRoomcode","FROM: $sEmail\r");
if ($sRoomcode == ALL) {
$query = "SELECT room_code FROM hotel_room_code WHERE user_id='$sUserID'";
$result=db_query($query);
$sRoomcode = mysql_fetch_row ($result);
$num=mysql_num_rows($result);
if (!$result) {
die('The programmer made a mistake: ' . mysql_error() );
}
}
$sql="SELECT * FROM availability WHERE user_id='$sUserID' AND room_code='$sRoomcode' AND start_date='$syear$smonth$sday'";
$result2=db_query($sql);
if (!$result2) {
$sql2="INSERT INTO availability (user_id,room_code,status,start_date,end_date) ".
"VALUES ('$sUserID','$sRoomcode','$status','$syear$smonth$sday','$eyear$emonth$eday')";
$result3=db_query($sql2);
$feedback .= " Successfully Added $num Availability. You Will Receive a Confirmation Email Soon ";
return true;
}
else {
$sql3="UPDATE availability SET status='$status',end_date='$eyear$emonth$eday'".
"WHERE user_id='$sUserID' AND room_code='$sRoomcode' AND start_date='$syear$smonth$sday'";
$result3=db_query($sql3);
$feedback .= " Successfully Updated $num Availability. You Will Receive a Confirmation Email Soon ";
return true;
}
} else {
$feedback .= ' ERROR - Must Fill In All Required Fields ';
return false;
}
}
Cheers
Ben