Okay, this is the first time I have tried to write a program this big before, as I am still fairly new at the whole PHP thing, I tried it a year or so ago then had to put it on hold until now so please be easy on me if this code is all messed up but constructive criticism is always welcomed . Anyways, The code shows all the data correctly, even the images. When I edit the text fields and hit the ‘edit’ button, it edits the database with no issues.
The problem is, that when ever I try and edit the images, it will not. It does not throw an error or anything, it just simply leaves the images alone. The images int he database are just point to a file location on the web server.(folders are named for the view they are holding, ie. ‘front’ is the folder name for the folder containing the front facing images)
Also, when I delete the record, is there a way to have it delete those images from the linked folder as well? I have messed with the ‘unlink’ function, but it did not seem to work right either.
Thank you guys very much for your time and help.
[php]<?PHP
ini_set(‘display_errors’, 0);
ob_start();
include(‘connection.php’);
$_id = (int)($_GET[‘id’]);
$_sql =“SELECT * FROM veh
WHERE id
=$_id”;
$_rs = mysql_query($_sql);
while($_rw = mysql_fetch_assoc($_rs))
{
$_id = $_rw[‘id’];
$_year = $_rw[‘year’];
$_make = $_rw[‘make’];
$_model = $_rw[‘model’];
$_style = $_rw[‘style’];
$_mileage = $_rw[‘mileage’];
$_color = $_rw[‘color’];
$_rprice = $_rw[‘rprice’];
$_front = $_rw['front'];
$_rear = $_rw['rear'];
$_left = $_rw['left'];
$_right = $_rw['right'];
$_intfront = $_rw['intfront'];
$_intrear = $_rw['intrear'];
}
?>
<?PHP
if(isset($_POST['edit']))
{
$_year = mysql_real_escape_string($_POST['_year']);
$_make = mysql_real_escape_string($_POST['_make']);
$_model = mysql_real_escape_string($_POST['_model']);
$_style = mysql_real_escape_string($_POST['_style']);
$_mielage = mysql_real_escape_string($_POST['_mileage']);
$_color = mysql_real_escape_string($_POST['_color']);
$_rprice = mysql_real_escape_string($_POST['_rprice']);
$_id = (int)$_POST['id'];
$image_location = $_POST['_front'];
$image_location2 = $_POST['_rear'];
$image_location3 = $_POST['_left'];
$image_location4 = $_POST['_rear'];
$image_location5 = $_POST['_intfront'];
$image_location6 = $_POST['_intrear'];
if(is_uploaded_file($_FILES['front']['tmp_name']))
{
$name = $_FILES['front']['name'];
$tmp_name = $_FILES['front']['tmp_name'];
$location = "front/$name";
move_uploaded_file($tmp_name,$location);
}
elseif($image_location != 'front/default.jpg'){$location = $image_location;}
else{$location = 'front/default.jpg';}
$_SQL = "UPDATE `veh` SET `year`='$_year',
`make`='$_make',
`model`='$_model',
`style`='$_style',
`mileage`='$_mileage',
`color`='$_color',
`rprice`='$_rprice',
`front`='$_front',
`rear`='$_rear',
`left`='$_left',
`right`='$_right',
`intfront`='$_intfront',
`intrear`='$_intrear'
WHERE `id`='$_id'";
mysql_query($_SQL) or die(mysql_error());
//header("Location : index.php?id=$_id");
$_html ="
RECORD HAS BEEN |
UPDATED CLICK HERE
|
";
}
elseif(isset($_POST['delete']))
{
$id = (int)$_POST['id'];
mysql_query("DELETE FROM `veh` WHERE `id`='$id' LIMIT 1");
$_html = 'Record deleted successfully!
Return to "View All" page.';
}
else
{
$_html="
Front:
![]()
|
|
|
|
|
Rear:
![]()
|
Left:
![]()
|
|
|
|
|
Right:
![]()
|
Left:
![]()
|
|
|
|
|
Right:
![]()
|
";
}
?>
<?php echo $_html; ?>[/php]