473,385 Members | 2,243 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,385 software developers and data experts.

Deleting Rows - Should be an easy one!

38
Hello folks,

Hopefully this will be an easy one for most of you guys. I don't delve into PHP much so I'd appreciate some help.

The aim of the script below is to display a collection of rows with the aim of specifying one for eventual deletion.

It returns the "row deleted" echo fine, but doesn't actually delete anything.

Expand|Select|Wrap|Line Numbers
  1.     <?
  2. include("connect.php"); 
  3.  
  4. if(!isset($cmd)) 
  5. {
  6.    $result = mysql_query("select * from events order by eventName"); 
  7.  
  8.    while($r=mysql_fetch_array($result)) 
  9.    { 
  10.  
  11.       $title=$r["eventName"];
  12.       $id=$r["eventNumber"];
  13.         $location=$r["eventLocation"];
  14.           $date=$r["eventDate"];
  15.  
  16.      echo "<span class='smalltitle'>$title</span><br><span class='bodytext'>$location<br>$date</span><br> "; 
  17.       echo "<a href='delete_event.php?cmd=delete&id=$id'>$title - Delete</a><br><br>";
  18.  
  19.     }
  20. }
  21. ?>
  22.  
Expand|Select|Wrap|Line Numbers
  1. <?
  2. if($_GET["cmd"]=="delete")
  3. {
  4.     $sql = "DELETE FROM events WHERE eventNumber=$id";
  5.     $result = mysql_query($sql);
  6.     echo "Row deleted!";
  7. }
  8. ?>
  9.  
Many thanks.
Aug 5 '09 #1
1 1428
Markus
6,050 Expert 4TB
If there's an error generated by mysql, it won't tell you - you have to find out for yourself.

Update your code to this:

Expand|Select|Wrap|Line Numbers
  1. <?
  2. if($_GET["cmd"]=="delete")
  3. {
  4.     $sql = "DELETE FROM events WHERE eventNumber=$id";
  5.     // Notice mysql_error()
  6.     $result = mysql_query($sql) or die("Error: ". mysql_error());
  7.     echo "Row deleted!";
  8. }
  9. ?>
Aug 5 '09 #2

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

Similar topics

3
by: ScottH | last post by:
I was looking for thw SQL to delete dupes from a table, and came across this. All who saw it agreed in principle, but I can't quite figure out the logic. If we are deleting all rows whose rowid...
5
by: Mojtaba Faridzad | last post by:
Hi, with SetDataBinding( ) a DataGrid shows a DataView. user can select some rows in the grid by holding cotrol key. when user clicks on Delete button, I should delete all selected rows. I am...
3
by: Chris Thunell | last post by:
I am trying to delete all the records in a table, but I keep getting a system.data.dbconcurrency exception. Is there an easy was to delete all the records in a sql table? Here is my code... i...
4
by: Geoff | last post by:
Hi I'm hoping somebody can help me with the following. I'm trying to delete all the rows in a dataview. There are 200 rows. Everything works fine until I delete half way through and then I'm...
2
by: Zak McGregor | last post by:
Hi all I have a table, for simplicity's sake containing one field, called unid. for example, select unid, oid from table gives me something like this: unid | oid ---------+---------
4
by: Jim Michaels | last post by:
Is it safe to do what is below? deleting from a resultset while you are processing it? I don't know how dynamic the SQL database is. I assume you get a cursor to live dataset. Even if it is a...
8
by: NAdir | last post by:
Hi, thank you for your help. My VB.Net application contains a document that the user can refresh at any time. The refresh works fine and needs to loop through few datatables (hundreds of rows)....
4
by: MiziaQ | last post by:
Hey, I'm using the following code to write entries to a data file and then read them in an msflexgrid. I now would like to add code under a delete button to use the table(grid) to delete rows from...
2
by: jodleren | last post by:
Hi! In a system, which collects data and the summarises it, we collect a large amount of data. Now, there seems to be a problem, when we try to delete just 16000 rows (entire table btw) or some...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.