473,666 Members | 2,284 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Delete script

155 New Member
I'm using the delete script below. It's deleting and sending the email OK, but the correct information is not being sent.

I tested this script on one database and it deleted several ads, but the email I received said that "No ads were deleted." How do I fix this?

delete_old.php:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include("dbconnect.php");
  3. $query = "DELETE FROM ads WHERE submitted < SUBDATE(NOW(), INTERVAL 45 DAY)";
  4. $result = mysql_query($query);
  5.  
  6. if (mysql_affected_rows() == 1)
  7. { // A record was deleted.
  8. $action = $result;
  9. } else {
  10. $action = "No ads were deleted.";
  11. }
  12.  
  13. // Send the email.
  14. $when = date('j M Y h:i:s A');
  15.  
  16. $email = "here@there.com";
  17. $subject = "Ad Deletion";
  18. $body = "Date: <b>$when</b><br><br> Results: $action";
  19. $headers = "From: there@here.com\n";
  20. $headers .= "Content-Type: text/html; charset=iso-8859-1\n";
  21. mail ($email, $subject, $body, $headers);
  22. ?>
Jan 14 '09 #1
1 1347
Markus
6,050 Recognized Expert Expert
It sounds like you're not being very specific with your DELETE clause. What I mean is, it looks like multiple records could be getting deleted. This would mean that mysql_affected_ rows() may not necessarily be 1, but greater than one. So, I suggest you edit your IF statement to check for a value of greater than 0 (hint: > 0).

Hope this helps,
Markus.
Jan 14 '09 #2

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

Similar topics

3
3200
by: lawrence | last post by:
I've two scripts, one to upload images, another to delete them. The upload script works fine, but the delete script has permissions trouble. How can PHP not have permission to delete an image it itself uploaded? Here is the delete script I'm using right now, and the error messages I got below.
12
3285
by: Gustaf Liljegren | last post by:
I've been learning using PHP and MySQL from the tutorial at freewebmasterhelp.com. Everything works fine, except deleting things. The script is invoked with a URL like this: http://www.example.org/test/delete_entry.php?id=35 And here's the script: <? include("dbinfo.inc.php");
12
4319
by: Apostolis K. | last post by:
I run windows XP and IIS 5.1 and the system doesn't let me to delete or move folders using FileSystemObject.DeleteFolder(path,force) or FileSystemObject.MoveFolder(origin,destination). I allow all permitions to that web folder (Read, Right, Source Access) I notice that in Windows XP cannot uncheck the Read-Only option in any folder options. If you uncheck and press OK the next time you open the folder properties again the check box will...
17
1741
by: mpar612 | last post by:
Hi everyone, I appreciate all of your help with me and the problems I have been having. I'm new to PHP and MySQL and I'm having some problems getting this script to work. I can't get this to work and I don't understand why. I don't get an error or anything, it almost seems like the page refreshes. I went to the phpmyadmin and the row is still in the database. The $_GET parts work perfectly in another script and the SQL statement...
0
1000
by: rajeshgujar | last post by:
Here is What needs to be Done In Your DataGrid do this 1 ] Private Sub DGReference_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DGReference.ItemDataBound e.Item.Cells(5).Attributes.Add("onclick", "return confirmDelete (this.form);") // If its the 5 th Column in the
15
3753
by: Morteneistrom | last post by:
Im a complete n00b at PHP so please forgive me if this i a stupid question Why wont the following work. PHP Code: <?php foreach (glob('../images/profil/*.jpg') as $filename) { echo "$filename <br>". "<a href="unlink('$filename');">Delete</ a>";
1
1086
by: Gandalf | last post by:
try this: foreach(glob('../galleri/galleri/*', GLOB_ONLYDIR) as $key=$dirname) { $table.=($count%1==0)?"</tr>\n<tr>\n":""; $table.="<td>".basename($dirname)."</td><td><input type='checkbox' name ='deldir' value='$dirname'></td>\n"; $count++; }
0
8443
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8356
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8781
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8550
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8639
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4366
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2769
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1772
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.