Author Topic: PHP/MySQL updating/deleting file with multiple image links.  (Read 688 times)

wilson382

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 649
  • Karma: 27
  • PHP Helper
    • View Profile
Re: PHP/MySQL updating/deleting file with multiple image links.
« Reply #15 on: August 28, 2012, 08:24:13 PM »
in your query

change
PHP Code: [Select]

 
`rear`='$image_location2'


to

PHP Code: [Select]

 
`rear`='$location2'
If help you, Click the [+] Karma to thanks me

willscarlet

  • Regular Member
  • **
  • Posts: 68
  • Karma: 0
    • View Profile
Re: PHP/MySQL updating/deleting file with multiple image links.
« Reply #16 on: August 28, 2012, 08:29:23 PM »
you mean change this line

PHP Code: [Select]
$image_location2 $_POST['_rear']; 

to

PHP Code: [Select]
$location2 $_POST['_rear']; 

wilson382

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 649
  • Karma: 27
  • PHP Helper
    • View Profile
Re: PHP/MySQL updating/deleting file with multiple image links.
« Reply #17 on: August 28, 2012, 08:34:21 PM »
well yeah change that as well but i what i mean is change it in your query

PHP Code: [Select]

  $_SQL 
"UPDATE `veh` SET `year`='$_year',  
                              `make`='
$_make',  
                              `model`='
$_model',  
                              `style`='
$_style',  
                              `mileage`='
$_mileage',  
                              `color`='
$_color', 
                              `rprice`='
$_rprice',  
                             
                            `front`='
$location', 
                            `rear`='
$image_location2', 
                             
                            `left`='
$image_location3', 
                            `right`='
$image_location4', 
                             
                            `intfront`='
$image_location5', 
                            `intrear`='
$image_location6
                             
                      WHERE `id`='
$_id'"

so change this
PHP Code: [Select]

 
`rear`='$image_location2'


to

PHP Code: [Select]

 
`rear`='$location2'

If help you, Click the [+] Karma to thanks me

willscarlet

  • Regular Member
  • **
  • Posts: 68
  • Karma: 0
    • View Profile
Re: PHP/MySQL updating/deleting file with multiple image links.
« Reply #18 on: August 28, 2012, 08:50:47 PM »
Haha, I can be really slow sometimes. I got it now :) The images update great, as well as the rest of the data. And the images delete like they should now. I don't suppose you could point me in the right direction to making that default.jpg image not get deleted?

I'd like it to stay there so if there are no images to upload, the user won't be looking at a red 'X'.

And thank you very very much for all your help on this.

wilson382

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 649
  • Karma: 27
  • PHP Helper
    • View Profile
Re: PHP/MySQL updating/deleting file with multiple image links.
« Reply #19 on: August 28, 2012, 11:04:58 PM »
I made a small function to help you

listen/read carefullyfollowing these steps

  • insert this function
    PHP Code: [Select]
    function GetFileName($f)
    {
    /* 
    * this function will get the name of a file
    * for Instance if the file is image14.jpg 
    * only image14 will be returned.

    BY wilson382
    */
    	
    $h=substr($f,strrpos($f,"/"),strrpos($f,"."));
    	
    $FileNamesubstr($h,1,strrpos($h,".")-1);
    	

    return 
    $FileName;
    }

    below this line in your script
    PHP Code: [Select]
     include('connection.php');
  • look for these code in your script
    PHP Code: [Select]
    	
    unlink($_POST['_front']);
    	
    unlink($_POST['_rear']);
    	
    unlink($_POST['_right']);
    	
    unlink($_POST['_left']);
    	
    unlink($_POST['_intfront']);
    	
    unlink($_POST['_intrear']);

    and replace them with
    PHP Code: [Select]

    	
    if (
    "default" != strtolower(GetFileName($_POST['_front']))){
    	
    unlink($_POST['_front']);
    	
    }
    	
    if (
    "default" != strtolower(GetFileName($_POST['_rear']))){
    	
    unlink($_POST['_rear']);
    	
    }
    	
    if (
    "default" != strtolower(GetFileName($_POST['_right']))){
    	
    unlink($_POST['_right']);
    	
    }
    	
    if (
    "default" != strtolower(GetFileName($_POST['_left']))){
    	
    unlink($_POST['_left']);
    	
    }
    	
    if (
    "default" != strtolower(GetFileName($_POST['_intfront']))){
    	
    unlink($_POST['_intfront']);
    	
    }
    	
    if (
    "default" != strtolower(GetFileName($_POST['_intrear']))){
    	
    unlink($_POST['_intrear']);
    	
    }
  • Save the file and see if still works lol
  • the default image should not be deleted
  • you are done
« Last Edit: August 28, 2012, 11:36:23 PM by wilson382 »
If help you, Click the [+] Karma to thanks me

willscarlet

  • Regular Member
  • **
  • Posts: 68
  • Karma: 0
    • View Profile
Re: PHP/MySQL updating/deleting file with multiple image links.
« Reply #20 on: August 29, 2012, 06:42:23 AM »
Works like a charm so far sir, thank you so much. So this kind of help is okay to get here? Wasn't too much for a new member to be asking?

and again, Thank you guys very much for all the help.

wilson382

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 649
  • Karma: 27
  • PHP Helper
    • View Profile
Re: PHP/MySQL updating/deleting file with multiple image links.
« Reply #21 on: August 29, 2012, 01:57:18 PM »
well i marked the thread solved glad that i helped you
If help you, Click the [+] Karma to thanks me