SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast gcarlyle's Avatar
    Join Date
    Mar 2002
    Location
    Olympia Wa
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ?id=$id&remove=yes

    Hi all,

    I have two scripts editshop.php and remove.php.

    In editshop.php I have a line like this.
    PHP Code:
    <a href='remove.php?id=$id&remove=yes'>X</a
    If the X if clicked the script directs you to remove.php.

    In remove.php

    I have this line:
    PHP Code:
    if($quantity == 0)
    {
    $query "DELETE FROM {$config["prefix"]}_boxes WHERE id = '$id'";
    $ret mysql_query($query); 
    This works about 80%of the time. It actually deletes the record in "boxes". Then it will just decides that it doesn't want to delete the record. I have to use phpMYAdmin and empty the table manually. Then it will work again.

    Any ideas why this happens?

    Thank
    Jennifer
    Wanna be php coder!

  2. #2
    SitePoint Wizard
    Join Date
    Jul 1999
    Location
    Chicago
    Posts
    2,629
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    if($quantity == 0)
    {
    $query "DELETE FROM {$config["prefix"]}_boxes WHERE id = '$id'";
    $ret mysql_query($query) or die mysql_error(); 
    Try this code. When you run it, it should print out any errors that it encountered in the query. Paste 'em back in here then.

  3. #3
    SitePoint Enthusiast gcarlyle's Avatar
    Join Date
    Mar 2002
    Location
    Olympia Wa
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is the whole snip.
    If it doesn't work it just updates boxes and subtracts 1 from the quantity then just leaves the record there with a 0 for quantity.
    I get no error.
    PHP Code:
    if($remove == yes)
    {
    $query "UPDATE {$config["prefix"]}_boxes set quantity = quantity - 1 WHERE id = '$id'";
    $ret mysql_query($query);

    if(
    $quantity == 0)
    {
    $query "DELETE FROM {$config["prefix"]}_boxes WHERE id = '$id'";
    $ret mysql_query($query) or die (mysql_error());
    }

    Wanna be php coder!

  4. #4
    gingham dress, army boots... silver trophy redux's Avatar
    Join Date
    Apr 2002
    Location
    Salford / Manchester / UK
    Posts
    4,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    maybe a silly question, but...do you actually assign the correct value to $quantity before you enter the if block ? on second look, this is probably what happens (and i'm guessing here, so bear with me if i'm off track):

    - you assign the current quantity to variable $quantity before the if block. now, say the quantity is 1...now $quantity=1
    - into the if block we go, and your update statement subtracts 1 from quantity IN THE DATABASE, so now in the db it's 0...however, your variable $quantity still equals 1
    - hence, the if($quantity == 0) block is skipped

    so, either you add a $quantity = $quantity -1; line after your UPDATE statement, OR you change you second if to if($quantity == 1).
    re·dux (adj.): brought back; returned. used postpositively
    [latin : re-, re- + dux, leader; see duke.]
    WaSP Accessibility Task Force Member
    splintered.co.uk | photographia.co.uk | redux.deviantart.com


Bookmarks

Posting Permissions

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