User needs to delete record

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nomad
    Recognized Expert Contributor
    • Mar 2007
    • 664

    User needs to delete record

    Hello Everyone:
    I'm working on a project for a client in which they want to add and delete events for a selected day on a calendar.
    I have built the calendar and added the events, but I'm having troubles deleting the event.
    I thought I could use the same code for adding the event and change some of the code.

    I get this error when doing so
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VALUES('adfadf ', '', '2008-9-4 1:00:00')' at line 1

    Here is my code
    [PHP]
    <html>
    <head>
    <title>Show/Delete Events</title>
    <head>
    <body>
    <h1>Show/Delete Events</h1>
    <?php
    $conn = mysql_connect(" localhost", "abc", "abc") or die(mysql_error ());
    mysql_select_db ("testDB",$conn ) or die(mysql_error ());

    //add any new event
    if ($_POST[op] == "do") {
    $event_date = $_POST[y]."-".$_POST[m]."-".$_POST[d]." ".$_POST[event_time_hh].":".$_POST[event_time_mm].":00";

    $insEvent = "DELETE FROM calendar_events VALUES('$_POST[event_title]', '$_POST[event_shortdesc]', '$event_date')" ;
    @mysql_query($i nsEvent) or die(mysql_error ());

    }

    //show events for this day
    $getEvent = "SELECT event_title, event_shortdesc , date_format(eve nt_start, '%l:%i %p') as fmt_date FROM calendar_events WHERE month(event_sta rt) = '$_GET[m]' AND dayofmonth(even t_start) = '$_GET[d]' AND year(event_star t) = '$_GET[y]' ORDER BY event_start";

    $getEvent_res = @mysql_query($g etEvent) or die(mysql_error ());

    if (@mysql_num_row s($getEvent_res ) > 0) {
    while ($ev = @mysql_fetch_ar ray($getEvent_r es)) {
    $event_title = stripslashes($e v['event_title']);
    $event_shortdes c = stripslashes($e v['event_shortdes c']);
    $fmt_date = $ev['fmt_date'];
    $event_txt .= "<P><strong>$fm t_date</strong>: $event_title<br >$event_shortde sc";

    }

    }

    if ($event_txt != "") {
    echo "<P><strong>Tod ay's Events:</strong>
    $event_txt
    <hr noshade width=80%>";
    }

    // show form for adding an event
    echo "<form method=post action=\"$_SERV ER[PHP_SELF]\">
    <P><strong>Woul d you like to delete an event?</strong><br>Comp lete the form below and press the submit button to add the event and refresh this window.</p>
    <p><strong>Even t Title:</strong><br>
    <input type=text name=event_titl e size=25 maxlength=25>
    <p><strong>Even t Description:</strong><br>
    <input type=text name=event_shor tdesc size=25 maxlength=255>
    <p><strong>Even t Time (hh:mm):</strong><br>
    <select name=event_time _hh>";
    for ($x=1; $x <= 24; $x++) {
    echo "<option value=\"$x\">$x </option>";
    }
    echo "</select> :
    <select name=event_time _mm>
    <option value=\"00\">00 </option>
    <option value=\"15\">15 </option>
    <option value=\"30\">30 </option>
    <option value=\"45\">45 </option>
    </select>
    <input type=hidden name=m value=$_GET[m]>
    <input type=hidden name=d value=$_GET[d]>
    <input type=hidden name=y value=$_GET[y]>
    <input type=hidden name=op value=do>
    <br><br>
    <input type=submit name=submit value=\"Delete Event\">
    </form>";
    ?>
    </body>
    </html>
    [/PHP]



    if i change this code
    [PHP]
    $insEvent = "DELETE FROM calendar_events WHERE('$_POST[event_title]', '$_POST[event_shortdesc]', '$event_date')" ;
    @mysql_query($i nsEvent) or die(mysql_error ());
    [/PHP]

    I get this
    Operand should contain 1 column(s)
    I don't know what that means?

    Thanks
    nomad
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Check out this mysql delete tutorial.

    Cheers.

    Comment

    • nomad
      Recognized Expert Contributor
      • Mar 2007
      • 664

      #3
      Originally posted by markusn00b
      Check out this mysql delete tutorial.

      Cheers.
      But I need the user to do this. The user does not know php so I need to have webpage where they can type in the info. and hit the submit button.

      Comment

      • stepterr
        New Member
        • Nov 2007
        • 157

        #4
        Originally posted by nomad
        But I need the user to do this. The user does not know php so I need to have webpage where they can type in the info. and hit the submit button.
        You have to tell the database what you are trying to delete. For example...

        [PHP]
        DELETE FROM calendar_events WHERE event_title = $_POST[event_title]
        [/PHP]

        Comment

        • Atli
          Recognized Expert Expert
          • Nov 2006
          • 5062

          #5
          Is all of the unfiltered user input that you are putting directly into DELETE statements not bothering anybody here but me?
          Sanitize that stuff before using it or you will end up with an extremely empty database.... or worse.

          Having said that.
          The problem with you original code is that the DELETE statement doesn't have a VALUES clause. See the Manual to see the proper syntax.
          stepterr's example shows the most common usage.

          You should also consider adding a LIMIT clause, just to make sure your entire table doesn't get wiped out if there is a problem.

          Comment

          Working...