Delete not working 
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
. It's being sent by - 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: - $sql = "DELETE image_name,b_width,b_height,t_width,t_height
-
FROM ads WHERE id='".$id."'";
-
$result = mysql_query($sql);
But this part is not working. Is there any obvious reason why?
| 
June 24th, 2009, 09:56 PM
|  | 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
| 
June 24th, 2009, 09:56 PM
|  | 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 This is a classified ads table which contains all the item's information.
The item's "id" is received on this delete page using
. It's being sent by - 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: - $sql = "DELETE image_name,b_width,b_height,t_width,t_height
-
FROM ads WHERE id='".$id."'";
-
$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. -
$result = mysql_query(...) or die(mysql_error());
-
| 
June 24th, 2009, 10:22 PM
| | Familiar Sight | | Join Date: Mar 2007
Posts: 146
| | | re: Delete not working
How would I sanitize that?
| 
June 24th, 2009, 10:43 PM
|  | 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 -
-
$sql = "DELETE FROM ads WHERE id='".$id."' ";
-
$result = mysql_query($sql);
-
-
| 
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. - $name = $_POST['name'];
-
$address1 = $_POST['address1'];
-
$address2 = $_POST['address2'];
-
$phone = $_POST['phone'];
-
$cell = $_POST['cell'];
-
-
// variables may have a value or they may be empty
-
-
query="UPDATE address_book SET
-
name='$name',
-
address1='$address1',
-
address2='$address2',
-
phone='$phone',
-
cell='$cell'
-
WHERE id='$id'";
| 
June 25th, 2009, 01:28 AM
|  | Familiar Sight | | Join Date: May 2009 Location: Wellington, New Zealand
Posts: 152
| | | re: Delete not working
cool ..that you wanted .. get some tutorial online |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,662 network members.
|