Connecting Tech Pros Worldwide Help | Site Map

Delete not working

  #1  
Old June 24th, 2009, 08:11 PM
Familiar Sight
 
Join Date: Mar 2007
Posts: 146
This is a classified ads table which contains all the item's information.

The item's "id" is received on this delete page using
Expand|Select|Wrap|Line Numbers
  1. $id = $_GET["id"];
. It's being sent by
Expand|Select|Wrap|Line Numbers
  1. delete_picture.php?id=$id
A query takes place which grabs the image_name from the database based on the id. Then it unlinks the images in the image/ and image/thumbs folders with this image_name. So the id variable is working, at least to this point.

Then it is suppose to perform this delete query:
Expand|Select|Wrap|Line Numbers
  1. $sql = "DELETE image_name,b_width,b_height,t_width,t_height
  2. FROM ads WHERE id='".$id."'"; 
  3. $result = mysql_query($sql);
But this part is not working. Is there any obvious reason why?
  #2  
Old June 24th, 2009, 09:56 PM
dlite922's Avatar
Expert
 
Join Date: Dec 2007
Location: Moon, Dark Side
Posts: 1,075

re: Delete not working


Ya you're delete is wrong.

See Manual: http://dev.mysql.com/doc/refman/5.0/en/delete.html

From what it looks like, you seem to select the image fields of the ads table to hopefully just delete those columns, and not the entire record.

That's now how MySQL works, a record must always have the same number of fields as the table allows although they can contain nothing (empty string, or NULL value)

Remember, Sanitize your inputs if I were to call your delete.php file like so

delete.php?id=1';DELETE FROM ads;

what do you think will happen? SQL Injection.

Good luck,



Dan
  #3  
Old June 24th, 2009, 09:56 PM
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,858
Provided Answers: 9

re: Delete not working


Quote:
Originally Posted by DavidPr View Post
This is a classified ads table which contains all the item's information.

The item's "id" is received on this delete page using
Expand|Select|Wrap|Line Numbers
  1. $id = $_GET["id"];
. It's being sent by
Expand|Select|Wrap|Line Numbers
  1. delete_picture.php?id=$id
A query takes place which grabs the image_name from the database based on the id. Then it unlinks the images in the image/ and image/thumbs folders with this image_name. So the id variable is working, at least to this point.

Then it is suppose to perform this delete query:
Expand|Select|Wrap|Line Numbers
  1. $sql = "DELETE image_name,b_width,b_height,t_width,t_height
  2. FROM ads WHERE id='".$id."'"; 
  3. $result = mysql_query($sql);
But this part is not working. Is there any obvious reason why?
Add 'or die(mysql_error());' to your mysql query to see if you a generating any errors.

Expand|Select|Wrap|Line Numbers
  1. $result = mysql_query(...) or die(mysql_error());
  2.  
  #4  
Old June 24th, 2009, 10:22 PM
Familiar Sight
 
Join Date: Mar 2007
Posts: 146

re: Delete not working


How would I sanitize that?
  #5  
Old June 24th, 2009, 10:43 PM
prabirchoudhury's Avatar
Familiar Sight
 
Join Date: May 2009
Location: Wellington, New Zealand
Posts: 152

re: Delete not working


Quote:
original
$sql = "DELETE image_name,b_width,b_height,t_width,t_height
FROM ads WHERE id='".$id."'";
$result = mysql_query($sql);

your delete query is wrong

may be

Expand|Select|Wrap|Line Numbers
  1.  
  2. $sql = "DELETE FROM ads WHERE id='".$id."' ";
  3. $result = mysql_query($sql);
  4.  
  5.  
  #6  
Old June 25th, 2009, 01:13 AM
Familiar Sight
 
Join Date: Mar 2007
Posts: 146

re: Delete not working


I found that UPDATE worked better than DELETE in this instance.
Expand|Select|Wrap|Line Numbers
  1. $name = $_POST['name'];
  2. $address1 = $_POST['address1'];
  3. $address2 = $_POST['address2'];
  4. $phone = $_POST['phone'];
  5. $cell = $_POST['cell'];
  6.  
  7. // variables may have a value or they may be empty
  8.  
  9. query="UPDATE address_book SET
  10. name='$name',
  11. address1='$address1',
  12. address2='$address2',
  13. phone='$phone',
  14. cell='$cell'
  15. WHERE id='$id'";
  #7  
Old June 25th, 2009, 01:28 AM
prabirchoudhury's Avatar
Familiar Sight
 
Join Date: May 2009
Location: Wellington, New Zealand
Posts: 152

re: Delete not working


cool ..that you wanted ..

get some tutorial online
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
Gridview Delete Not Working and no Error DAnDA answers 2 October 27th, 2007 02:42 PM
Delete not working from ForView through ObjectDataSource Shane_SDE answers 0 May 3rd, 2006 07:57 PM
File.Delete not working on Window Server 2003 Eric Bettan answers 1 November 19th, 2005 01:45 PM
foreign key contraints, on delete cascade not working? Andrew DeFaria answers 5 July 20th, 2005 12:45 AM