PHP Programming > General PHP Help

PHP/MySQL updating/deleting file with multiple image links.

(1/5) > >>

willscarlet:
Hello, I am new here so I didn't want to go posting tons of code for help without asking first.

I have started a 'car dealership inventory' program for a learning project but im stuck. The program is simple, it allows you to view all vehicle inventory or search the inventory database. Logging in as admin allows y ou to enter the vehicles into the database, as well as modify and/or delete the records.

The code will let users search and view all, it will allow admin to enter records into the database, but it will not allow them to delete or modify the record at all, also using the unlink function it is supposed to delete the images stored in their file locations when the record is deleted from the database.

Is this the kind of thinkg I can get help with here? or is that a bit much?

anyways, I thank you all for your time and help :)

wilson382:
quite interesting and easy.

do you need a start up advise/suggestion? or do you have codes already?

willscarlet:
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 Code: ---<?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 ="<tabel><tr>  
       <td width=\"19%\">RECORD HAS BEEN </td> 
       <td width=\"81%\">UPDATED CLICK <a href=\"viewall.php\">HERE</a></td> 
     </tr></table>"; 

elseif(isset($_POST['delete'])) 

    $id = (int)$_POST['id']; 
    mysql_query("DELETE FROM `veh` WHERE `id`='$id' LIMIT 1"); 
    $_html = 'Record deleted successfully!<br/><a href="viewall.php">Return to "View All" page.</a>'; 


else 

$_html=" 
<form action=\"\" method=\"post\" id=\"_form\" name=\"_form\" enctype=\"multipart/form-data\"> 

<table> 
<tr>  
<td><b><i><u><font size=2>Year:</font></u></i></b><br><input type=\"text\" name=\"_year\" value=\"$_year\"/><br></td> 
<td> &nbsp; </td> 
<td><b><i><u><font size=2>Make:</font></u></i></b><br><input type=\"text\" name=\"_make\" value=\"$_make\"/><br></td> 
<td> &nbsp; </td> 
<td><b><i><u><font size=2>Model:</font></u></i></b><br><input type=\"text\" name=\"_model\" value=\"$_model\"/><br></td> 
</tr></table> 
<br> 

<table> 
<tr>  
<td><b><i><u><font size=2>Style:</font></u></i></b><br><input type=\"text\" name=\"_style\" value=\"$_style\"/><br></td> 
<td> &nbsp; </td> 
<td><b><i><u><font size=2>Mileage:</font></u></i></b><br><input type=\"text\" name=\"_mileage\" value=\"$_mileage\"/><br></td> 
<td> &nbsp; </td> 
<td><b><i><u><font size=2>Color</font></u></i></b><br><input type=\"text\" name=\"_color\" value=\"$_color\"/><br></td> 
</tr></table> 
<br> 

<table> 
<tr>  
<td><b><i><u><font size=2>Retail Price:</font></u></i></b><br><input type=\"text\" name=\"_rprice\" value=\"$_rprice\"/><br></td> 
</tr></table> 
<br> 

<table> 
<tr>  
<td><b><i><u><font size=2>Front:</font></u></i></b><br><img src = ".$_front." height = 250 width = 250><br><input type='file' name='front' /><br></td> 
<td> &nbsp; </td><td> &nbsp; </td><td> &nbsp; </td><td> &nbsp; </td> 
<td><b><i><u><font size=2>Rear:</font></u></i></b><br><img src = ".$_rear." height = 250 width = 250><br><input type='file' name='rear' /><br></td> 
</tr></table>  
<br> 

<table> 
<tr>  
<td><b><i><u><font size=2>Left:</font></u></i></b><br><img src = ".$_left." height = 250 width = 250><br><input type='file' name='left' /><br></td> 
<td> &nbsp; </td><td> &nbsp; </td><td> &nbsp; </td><td> &nbsp; </td> 
<td><b><i><u><font size=2>Right:</font></u></i></b><br><img src = ".$_right." height = 250 width = 250><br><input type='file' name='right' /><br></td> 
</tr></table>  
<br> 

<table> 
<tr>  
<td><b><i><u><font size=2>Left:</font></u></i></b><br><img src = ".$_intfront." height = 250 width = 250><br><input type='file' name='intfront' /><br></td> 
<td> &nbsp; </td><td> &nbsp; </td><td> &nbsp; </td><td> &nbsp; </td> 
<td><b><i><u><font size=2>Right:</font></u></i></b><br><img src = ".$_intrear." height = 250 width = 250><br><input type='file' name='intrear' /><br></td> 
</tr></table>  
<br> 

<br> 
<input type=\"submit\" align = \"left\" name=\"edit\" value=\"Edit\"/> 
<input type=\"hidden\" name=\"id\" value=\"$_id\"/> 

<input type=\"hidden\" name=\"_front\" value=\"$_front\"/> 

<input type=\"hidden\" name=\"edit\" value=\"edit\"/> 

</form> 
<form id=\"d\" action=\"\" method=\"post\" valign = \"top\"><input type=\"submit\" id=\"delete\" name=\"delete\" value=\"Delete\"/> 
<input type=\"hidden\" name=\"id\" value=\"$_id\" /></table></form>"; 


?> 

<script type="text/javascript"> 
$('#d').submit(function(){ 
    if(confirm("Are you sure?")) 
         return true; 
     else 
         return false; 
}); 
</script> 

<?php echo $_html; ?>
--- End code ---

wilson382:
how many images can a single record have?

willscarlet:
6 images. a front, rear, left, right, interior front, and interior rear view.

Navigation

[0] Message Index

[#] Next page

Go to full version