SitePoint Sponsor

User Tag List

Results 1 to 11 of 11

Thread: Remove via Form

  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2002
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Remove via Form

    Alright I searched throuhg the boards and found some information on this but nothing worked quite how I want this to work.

    I have a page called remove.php. It's sole purpose is to be on simple form with a date field. When submitted I want to remove the row with a specific 'date' from teh table.

    Here's the code I'm using for it:

    PHP Code:
    <?php

    if ($submit) {

      
    // process form

      
    $db mysql_connect("localhost""jagzone""password");

      
    mysql_select_db("jagzone",$db);

      
    mysql_query("DELETE FROM 'magilla' WHERE 'date'='$remove' LIMIT 1");

      echo 
    "Record Deleted!";

    } else{
    ?>
      <form method="post" action="<?php echo $PHP_SELF?>">
    <p>Date To Be Removed: <input name="$remove" size="10"></p>
    <input type="Submit" name="submit" value="Delete Date">
    </form>
    <?php
    }
    ?>
    I've tried using both DELETE FROM and REMOVE From. I get no errors when I run it and A screen comes up saying Record Deleted like it's suppose to yet the record does not delete. I also enter the date exactly as it is in the table

    This is also the exact code I use for Submitting information into the table except I am using the insert command and have many more variables.

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    Salt Lake City Utah
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It is saying "Record Deleted" because you are telling it to.

    In order for it to only echo that IF it was deleted, then you need to modify your code something like:

    [PHP]if (mysql_query("foofoo")){
    echo "Record Deleted";
    }

    or thereabouts.

    I normally do ASP a lot more, so the exact syntax will be rusty, but it is the general idea.

    mysql_query returns a 1 if completed, or a 0 if not - I believe.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2002
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now I've got a bigger problem:

    Here's my code now:

    PHP Code:
    <?php

    if ($submit) {

      
    // process form

      
    $db mysql_connect("localhost""jagzone""password");

      
    mysql_select_db("jagzone",$db);

      
    $query=mysql_query("DELETE FROM 'magilla' WHERE 'date'='$remove' LIMIT 1");

        if (!
    $query)
    {
    echo(
    "<P>Error performing query: " .         mysql_error() . "</P>");    exit();
    }

    else{echo 
    "Record Deleted!";}
    }

     else{
    ?>
      <form method="post" action="<?php echo $PHP_SELF?>">
    <p>Date To Be Removed: <input name="remove" size="10"></p>
    <input type="Submit" name="submit" value="Delete Date">
    </form>
    <?php
    }
    ?>
    Now when I go to the page I get:
    Error performing query: You have an error in your SQL syntax near ''magilla' WHERE 'date'='' LIMIT 1' at line 1
    How am i suppose to tell it I want to remove the date that is in the form when I press Submit? I'm sure it's something so simple yet It's giving me such a headache

  4. #4
    SitePoint Enthusiast
    Join Date
    Jan 2002
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I figured out I could do it just by using the code below but for some reason it says i have an error in my_SQL syntax. I know the syntax should e right since I ran the code in PHPmyAdmin and it asked if I wanted to delete the record

    PHP Code:
    <?php

      $db 
    mysql_connect("localhost""jagzone""pass");

      
    mysql_select_db("jagzone",$db);

      
    $query=mysql_query("DELETE FROM 'magilla' WHERE 'date'='$remove' LIMIT 1");

        if (!
    $query)
    {
    echo(
    "<P>Error performing query: " .         mysql_error() . "</P>");    exit();
    }

    else{echo 
    "Record Deleted!";}

    ?>
    And the error is now:
    Error performing query: You have an error in your SQL syntax near ''magilla' WHERE 'date'='08.20.02' LIMIT 1' at line 1
    In the URL the address is http://www.website.com/removetest.php?remove=08.20.02

    That date is in teh database exactly like that
    I know I'm prolly seeming like a complete pain but this is driving me crazy
    Last edited by JagZone; Mar 6, 2002 at 22:55.

  5. #5
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    Salt Lake City Utah
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    and perhaps

    if (isset($remove)) {
    }

    to make sure the value is passed

    it appears from your error message that the date is not being passed to the query -


    quote:
    --------------------------------------------------------------------------------

    Error performing query: You have an error in your SQL syntax near ''magilla' WHERE 'date'='' LIMIT 1' at line 1

    --------------------------------------------------------------------------------



    'date'='' is a clue to that

  6. #6
    SitePoint Enthusiast
    Join Date
    Jan 2002
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    but in my last one, the error came up with the date in it:

    Error performing query: You have an error in your SQL syntax near ''magilla' WHERE 'date'='08.20.02' LIMIT 1' at line 1

  7. #7
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    Salt Lake City Utah
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy posts crossed

    yeah, see that now - must have come up while I typed this one...

    ooooo, - is that a valid date?

    from MySQL Documentation:

    http://www.mysql.com/documentation/m....html#DATETIME


    Note:
    As a string in either 'YYYY-MM-DD' or 'YY-MM-DD' format. A ``relaxed'' syntax is allowed here, too. For example, '98-12-31', '98.12.31', '98/12/31', and '98@12@31' are equivalent.

  8. #8
    SitePoint Enthusiast
    Join Date
    Jan 2002
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well I have it classified as a varchar field so that I could easily make it in mm.dd.yy format. So its a valid field as well.

  9. #9
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    Salt Lake City Utah
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    OIC

    oic - hmmm,

    I think I see it now...

    try this

    "DELETE FROM magilla WHERE date='$remove' LIMIT 1"

    I dug around in a PHP/MySQL project I did last year and noticed that there are no '' around the table and column names.

  10. #10
    SitePoint Enthusiast
    Join Date
    Jan 2002
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    THAT DID IT! Thanks a bunch, I thought i had tried that before but must not have.

    I'd still like to eventually do that via a form instead of through the URL but for now that works great!

  11. #11
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    Salt Lake City Utah
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Wink Glad to help!

    Hey, just glad it worked - Later...


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
  •