Since migrating to a newer server with PHP 5.3 from a server with PHP 4.4, this site has completely broken. One of the main functionalities is to update records. When I click on the button for update record, the page refreshes, and the values are still exactly the same as they were before I try to change a word in a textbox.
I am aware that this code is not best practice, but this site is getting a facelift and will no longer use any of the gross code. If I was a php developer, I’m sure I would know what to do with this, but I’m not. I was just assigned the task to fix it.
I would really appreciate some help here because I am lost. I created a test page that includes this file so that I can show the errors and there are none!
Here is the update function that I cannot get to work.
[php]
function updRec($ver) {
include ‘db_connect.php’;
extract ($_POST);
$chk = ((10 * 10) * 20 + 50) - 24;
if ($logged_in == 0 || strlen($_SESSION['username']) < 4 || $ver != $chk) {
audit_upd("Invalid Login Information - updRec() function", $db_object);
die("Illegal Access");
} else {
audit_upd("Accessed: updRec() function", $db_object);
}
global $id, $unittype, $unitname, $unitaddress, $unitlocation, $unitzip,
$unitprofile, $unitbeds, $unitbaths, $unitbathx, $unitsize, $pets, $smoke, $rentamt,
$contactname, $phone1, $phone1type, $phone2, $phone2type, $phone3, $phone3type, $email, $registerdate, $status;
global $PHP_SELF;
include “globalizePOSTGET.php”;
/*if (isset($_POST[‘id’])) $id = $_POST[“id”];
if (isset($_POST[‘unittype’])) $unittype = $_POST[“unittype”];
if (isset($_POST[‘unitname’])) $unitname = $_POST[“unitname”];
if (isset($_POST[‘unitaddress’])) $unitaddress = $_POST[“unitaddress”];
if (isset($_POST[‘unitlocation’])) $unitlocation = $_POST[“unitlocation”];
if (isset($_POST[‘unitzip’])) $unitzip = $_POST[“unitzip”];
if (isset($_POST[‘unitprofile’])) $unitprofile = $_POST[“unitprofile”];
if (isset($_POST[‘unitbeds’])) $unitbeds = $_POST[“unitbeds”];
if (isset($_POST[‘unitbaths’])) $unitbaths = $_POST[“unitbaths”];
if (isset($_POST[‘unitbathx’])) $unitbathx = $_POST[“unitbathx”];
if (isset($_POST[‘unitsize’])) $unitsize = $_POST[“unitsize”];
if (isset($_POST[‘pets’])) $pets = $_POST[“pets”];
if (isset($_POST[‘smoke’])) $smoke = $_POST[“smoke”];
if (isset($_POST[‘rentamt’])) $rentamt = $_POST[“rentamt”];
if (isset($_POST[‘contactname’])) $contactname = $_POST[“contactname”];
if (isset($_POST[‘phone1’])) $phone1 = $_POST[“phone1”];
if (isset($_POST[‘phone1type’])) $phone1type = $_POST[“phone1type”];
if (isset($_POST[‘phone2’])) $phone2 = $_POST[“phone2”];
if (isset($_POST[‘phone2type’])) $phone2type = $_POST[“phone2type”];
if (isset($_POST[‘phone3’])) $phone3 = $_POST[“phone3”];
if (isset($_POST[‘phone3type’])) $phone3type = $_POST[“phone3type”];
if (isset($_POST[‘email’])) $email = $_POST[“email”];
if (isset($_POST[‘registerdate’])) $registerdate = $_POST[“registerdate”];
if (isset($_POST[‘status’])) $status = $_POST[“status”]; */
if(empty($id)) error_message(‘Empty Unit ID!’);
// no HTML tags
$unitname = strip_tags($unitname);
$unitaddress = strip_tags($unitaddress);
$contactname = strip_tags($contactname);
$email = strip_tags($email);
if (!get_magic_quotes_gpc()) {
$unitname = addslashes($unitname);
$unitaddress = addslashes($unitaddress);
$contactname = addslashes($contactname);
$email = addslashes($email);
$unitprofile = addslashes($unitprofile);
}
if(empty($unitname)) $unitname = "Rental Unit";
if(empty($unitprofile)) $unitprofile = "No Profile.";
$store_dt = substr($registerdate, 6, 4).'-'.substr($registerdate, 0, 2).'-'.substr($registerdate, 3, 2);
$rentamt = str_replace(",", "", $rentamt);
$field_str = ‘’;
$field_str .= " unittype = ‘$unittype’, ";
$field_str .= " unitname = ‘$unitname’, ";
$field_str .= " unitaddress = ‘$unitaddress’, ";
$field_str .= " unitlocation = ‘$unitlocation’, ";
$field_str .= " unitzip = ‘$unitzip’, ";
$field_str .= " unitprofile = ‘$unitprofile’, ";
$field_str .= " unitbeds = ‘$unitbeds’, ";
$field_str .= " unitbaths = ‘$unitbaths’, ";
$field_str .= " unitbathx = ‘$unitbathx’, ";
$field_str .= " unitsize = ‘$unitsize’, ";
$field_str .= " pets = ‘$pets’, ";
$field_str .= " smoke = ‘$smoke’, ";
$field_str .= " rentamt = ‘$rentamt’, ";
$field_str .= " contactname = ‘$contactname’, ";
$field_str .= " phone1 = ‘$phone1’, ";
$field_str .= " phone1type = ‘$phone1type’, ";
$field_str .= " phone2 = ‘$phone2’, ";
$field_str .= " phone2type = ‘$phone2type’, ";
$field_str .= " phone3 = ‘$phone3’, ";
$field_str .= " phone3type = ‘$phone3type’, ";
$field_str .= " email = ‘$email’, ";
$field_str .= " registerdate = ‘$store_dt’, ";
$field_str .= " status = ‘$status’, ";
$field_str .= " accessdate = Now() ";
$query = “UPDATE $tbl_units SET $field_str WHERE id = ‘$id’” or die(mysql_error());
$upd_member = mysql_query($query);
if(!$upd_member){
error_message(mysql_error());
}
$num_rows = mysql_affected_rows();
if(!$num_rows) {
error_message(“Nothing was updated!”);
}
mysql_close();
echo "<script>alert('Unit record updated successfully!'); location.replace('memonly.php?action=');</script>";
}
[/php]
And here is the form that used to allow editing and deleting records.
[code]
RENTAL UNIT | |
---|---|
Registration Date* | |
Type* | <?php for($i=0; $i < count($unit_array); $i++) { if($unittype == $unit_array[$i]) { echo "" . $unit_array[$i] . "\n"; } else { echo "" . $unit_array[$i] . "\n"; } } ?> |
Unit Name* | |
Unit Address* | |
Location* | <?php for($i=0; $i < count($location_array); $i++) { if($unitlocation == $location_array[$i]) { echo "" . $location_array[$i] . "\n"; } else { echo "" . $location_array[$i] . "\n"; } } ?> |
Unit Zip Code* | |
Total Bedrooms* | |
Total Bathrooms* | value="1/4">1/4 value="1/2">1/2 value="3/4">3/4 |
Unit Size (sq.ft.)* | |
Allow Pets | >Yes >Yes, with restrictions >No |
Allow Smoking | >Yes >No |
Other Description | <?php echo $unitprofile; ?> |
Rent Amount |
RENTAL UNIT PHOTOS | |||
---|---|---|---|
(Click photo for better view) | |||
<?php if(!empty($photo1)) { echo ""; } else { echo ""; } ?> | <?php if(!empty($photo2)) { echo ""; } else { echo ""; } ?> | <?php if(!empty($photo3)) { echo ""; } else { echo ""; } ?> | <?php if(!empty($photo4)) { echo ""; } else { echo ""; } ?> |
<?php if(!empty($photo1)) { echo "Change Photo"; } else { echo "Update above photo..."; } ?> | <?php if(!empty($photo2)) { echo "Change Photo"; } else { echo "Update above photo..."; } ?> | <?php if(!empty($photo3)) { echo "Change Photo"; } else { echo "Update above photo..."; } ?> | <?php if(!empty($photo4)) { echo "Change Photo"; } else { echo "Update above photo..."; } ?> |
<?php if(!empty($photo1)) { echo "Delete Photo"; } ?> | <?php if(!empty($photo2)) { echo "Delete Photo"; } ?> | <?php if(!empty($photo3)) { echo "Delete Photo"; } ?> | <?php if(!empty($photo4)) { echo "Delete Photo"; } ?> |
CONTACT PERSON | |
---|---|
Name* | |
<?php for($i=0; $i < count($phone_array); $i++) { if($phone1type == $phone_array[$i]) { echo "" . $phone_array[$i] . "\n"; } else { echo "" . $phone_array[$i] . "\n"; } } ?> Phone | |
<?php for($i=0; $i < count($phone_array); $i++) { if($phone2type == $phone_array[$i]) { echo "" . $phone_array[$i] . "\n"; } else { echo "" . $phone_array[$i] . "\n"; } } ?> Phone | |
<?php for($i=0; $i < count($phone_array); $i++) { if($phone3type == $phone_array[$i]) { echo "" . $phone_array[$i] . "\n"; } else { echo "" . $phone_array[$i] . "\n"; } } ?> Phone | |
Status* |
>Available >Inactive >Rented |