www.webdeveloper.com
Results 1 to 5 of 5

Thread: delete items options

  1. #1
    Join Date
    Aug 2006
    Posts
    57

    delete items options

    hi, I have tried to send single to php to delete items from html but is seemed to me is not sending to delete it and there is no errors at all can you see code what did i missed!

    in body

    HTML Code:
      <td width="12%" align="center"><input type="submit" name="yesdelete" id="deleteid" value="Submit" />
    in php

    PHP Code:
    <?php
    if (isset($_POST['yesdelete'])) {
    //////////////////////////////////////////////////////////
    // remove item from system and delete its picture
    // delete from database
    //////////////////////////////////////////////////////////
        
        
    $id_to_delete $_GET['yesdelete'];
        if (
    $id_to_delete $mysqli->query("DELETE FROM product WHERE product_id='$id_to_delete' LIMIT 1"))
    /////////////////////////////////////////////////////////////
    // unlink the image from server
    // Remove The Pic -------------------------------------------
    /////////////////////////////////////////////////////////////
        
        
    $pictodelete = ("../product_images/$id_to_delete.jpg");
        if (
    file_exists($pictodelete)) {
                       
    unlink($pictodelete);
        }
        
    header("location: product-copy-4.php"); 
        exit();
    }
    ?>

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    890
    You are wiping out the value of $id_to_delete when you run your query. Silly Silly Silly

  3. #3
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    795
    From the html sample you gave, I don't see how this is going to work at all....

    First of all your checking if the value was sent using the POST method:

    PHP Code:
    if (isset($_POST['yesdelete'])) { 
    Then you're pulling the actual value from the passed querystring (GET)

    PHP Code:
    $id_to_delete $_GET['yesdelete']; 
    If for some reason this is actually correct, the value you're sending is "Submit"

    Code:
    <input type="submit" name="yesdelete" id="deleteid" value="Submit" />
    Also, I would remove the "LIMIT 1" from the DELETE SQL statement, I don't think that's valid (I stand to be corrected)?

  4. #4
    Join Date
    Nov 2013
    Posts
    33
    you can use LIMIT with single int values in a DELETE query, unlike a SELECT where you can use a range

  5. #5
    Join Date
    Nov 2013
    Posts
    33
    as @bionoid's said your mixing request variables.
    if your using get use $_GET or if your using post $_POST
    PHP Code:
    <?php 
    if (isset($_GET['submit'])) { 
    ////////////////////////////////////////////////////////// 
    // remove item from system and delete its picture 
    // delete from database 
    ////////////////////////////////////////////////////////// 
         
        
    $id_to_delete = (int) $_GET['yesdelete']; //cast to int to prevent type conflict should really do high level error checking tbh
        
    if ($id_to_delete $mysqli->query("DELETE FROM product WHERE product_id='$id_to_delete' LIMIT 1")) 
    ///////////////////////////////////////////////////////////// 
    // unlink the image from server 
    // Remove The Pic ------------------------------------------- 
    ///////////////////////////////////////////////////////////// 
         
        
    $pictodelete = ("../product_images/$id_to_delete.jpg"); 
        if (
    file_exists($pictodelete)) { 
                       
    unlink($pictodelete); 
        } 
        
    header("location: product-copy-4.php");  
        exit(); 

    ?>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles