You are here: Re: [PHP] error when trying to delete a record « PHP « IT news, forums, messages
Re: [PHP] error when trying to delete a record

Posted by "Mark Rees" on 07/11/05 17:25

""Jay Blanchard"" <jay.blanchard@niicommunications.com> wrote in message
news:C8F323573C030A448F3E5A2B6FE2070B08EB9514@nemesis...
[snip]
$query= "DELETE FROM sheet1 WHERE id=$id";

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 '' at line 1
[/snip]

try...

$query= "DELETE FROM sheet1 WHERE id = '".$id."' ";

Note the single quotes around conditional data. Imagine if $id = 1 and
you did your original query, it would read...

$query= "DELETE FROM sheet1 WHERE id=1";

Which is where id = TRUE. You could end up deleting all of the records
in the database.

---

Is the above statement true when the id field is numeric (which it surely is
in this case)? I get the expected results (in mySQL) when using statements
like

SELECT name FROM table WHERE id=1

with no single quotes round it. Putting quotes round integer values is
counter-intuitive - is it necessary in some cases?

---

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация