473,325 Members | 2,442 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

User needs to delete record

nomad
664 Expert 512MB
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($insEvent) or die(mysql_error());

}

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

$getEvent_res = @mysql_query($getEvent) or die(mysql_error());

if (@mysql_num_rows($getEvent_res) > 0) {
while ($ev = @mysql_fetch_array($getEvent_res)) {
$event_title = stripslashes($ev['event_title']);
$event_shortdesc = stripslashes($ev['event_shortdesc']);
$fmt_date = $ev['fmt_date'];
$event_txt .= "<P><strong>$fmt_date</strong>: $event_title<br>$event_shortdesc";

}

}

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

// show form for adding an event
echo "<form method=post action=\"$_SERVER[PHP_SELF]\">
<P><strong>Would you like to delete an event?</strong><br>Complete the form below and press the submit button to add the event and refresh this window.</p>
<p><strong>Event Title:</strong><br>
<input type=text name=event_title size=25 maxlength=25>
<p><strong>Event Description:</strong><br>
<input type=text name=event_shortdesc size=25 maxlength=255>
<p><strong>Event 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($insEvent) or die(mysql_error());
[/PHP]

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

Thanks
nomad
Sep 16 '08 #1
4 2292
Markus
6,050 Expert 4TB
Check out this mysql delete tutorial.

Cheers.
Sep 16 '08 #2
nomad
664 Expert 512MB
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.
Sep 16 '08 #3
stepterr
157 100+
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]
Sep 16 '08 #4
Atli
5,058 Expert 4TB
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.
Sep 17 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Steve | last post by:
I have several pairs of synchronized subforms in an application. I have a Delete button for each pair that uses the following code or similar to delete a record in the second subform: ...
1
by: CFW | last post by:
I have read as much as I could find here and in Tony's site as well - being directed there from here. I have a three user database with a BE .mdb (Access 2K) in a share on one PC and each user...
13
by: Mickey | last post by:
Hi all, Currently I use a timestamp to log users out after 15 minutes of inactivity. However I also need to log a user out if they have just left the page. I need to do this because I store...
3
by: penguin732901 | last post by:
What do experienced programmers find the most efficient way to handle user settings. Currently I have 4 tables which allow various clients to customize my program to work for them,...
1
by: capdownlondon | last post by:
Im using the following code to duplicate a record varCnt(retrieved from a combo box on the form) many times, and it only duplicates the record with the fields present on the form for that record....
1
by: commodityintelligence | last post by:
Greetings, I am merging a series of different tables into one query to export decision-making information. I have some architecture issues I need to ask for help on. I have no programming...
3
by: mmckinnon | last post by:
Hi All, This is really basic but I'm having trouble finding a straight forward way to do this. I have an Access application where the for is in spreadsheet mode. When a user leaves a control...
5
by: Jim | last post by:
Hi, Just wondering which is better vector<record *r; r.push_back(new record(x,y)); or vector<recordr; r.push_back(record(x,y));
5
by: agarwasa2008 | last post by:
Hi, I would like to delete a record based on a user entered string. Here are the details. I have a txtFind textbox. A string is entered by the user. Based on that string value it displays that...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.