First of all, make a copy of your database to test things. Never test code
on production enviroment.

  Then, the delete syntax most of the time is:

  DELETE FROM table_name WHERE column = 'value';

  Let's see:

<?php
$table = 'table_name';
$value = '15';

$sql = "DELETE FROM $table WHERE field_1 = '$value'";
mysql_query($sql) or exit(mysql_error());
?>

  There isn't a space between field and 1, at least I don't think SQL
compliant databases let you put spaces on table and column names. $value
probaly should be between single quotes, Mysql requires it for strings or
values that are compared to a string type-column (varchar, text, etc...).
Even sometimes for numeric columns, so, doesn't hurt to leave it unless it
doesn't work ;-)

  If $table is not recognized, try:

$sql = 'DELETE FROM ' . $table . " WHERE field_1 = '$value'";

  If you just want to delete one record, it's a good idea to put a LIMIT 1
at the end.

  Hope it helps!

--

Julio Nobrega.

Um dia eu chego lá:
http://sourceforge.net/projects/toca

Ajudei? Salvei? Que tal um presentinho?
http://www.submarino.com.br/wishlistclient.asp?wlid=664176742884


"Chuck "Pup" Payne" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]...
> Hi,
>
> I a seting up a php page that will let me delete a record from my mysql
> database, but I want it be able to match to fields before it will let a
user
> delete that record. I know the basic sql command is....
>
> DELETE FROM $table WHERE field 1 = "$value"
>
> But I don't know how to write the state for a second field. Can some one
> tell, but one field seem to give too much choose and would make it to easy
> to delete the wrong record.
>
>
>  ----------------------------
>  | Chuck Payne              |
>  | Magi Design and Support  |
>  | [EMAIL PROTECTED]   |
>  ----------------------------
>
> BeOS, Macintosh 68K, Classic, and OS X, Linux Support.
> Web Design you can afford.
>
> "Never be bullied into silence. Never allow yourself to be made a victim.
> Accept no one's definition of your life; define yourself."- Harvey
Fierstein
>
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to