Well, you could go to www.hotscripts.com/PHP article and tutorials

  But it is easy.

  Delete syntax is:

  This will boom every record.
  DELETE FROM table;

  This will boom every Joe:
  DELETE FROM table WHERE name='Joe';

  This will boom an id. That's probaly the way you want. Also it ensures (if
your id collumn is a PRIMARY or UNIQUE column) that the desired client will
be deleted:
  DELETE FROM table WHERE id='$id';

  But, what is $id? It's a value that you passed, for example, via a form.

<form name="boom" method="post" action="boom.php">
  <select name="id">
    $sql = 'SELECT id, name, last_name FROM table';
    $res = mysql_query($sql);
    while (list($id, $name, $last_name) = mysql_fetch_array($res)) {
        echo "<option value=\"$id\">$last_name, $name</option>";

  Or your prefered way of passing the id value.

  On boom.php:

$sql = "DELETE FROM table WHERE id='$id'";

  But let's say you didn't make a client id field (wich is generally bad
practice), but you have the EXACTLY name, last name and address. I stress
the importance of exactly because the following line would not delete
'Street' if the value is 'Str.':

$sql = "DELETE FROM table WHERE name='$name' AND last_name = '$last_name'
AND address = '$address'";

  To make simpler for who's going to use the system, an idea. When
displaying client search results, put a little text/icon/image close to the
client name. A link like:

<a href="boom.php?id=<?php echo $id; ?>">Boom this!</a>

  Where $id is that field you got from your Primary or Unique mysql table

  Well, that pretty much is the basic. The most important part if the WHERE
part of the sql clause. Just get it right and everything will be fine.

  And remember, never test anything like this on production enviroments! As
'DELETE FROM table' is evil.


Julio Nobrega

Don't eat the yellow snow.

"Chip Wiegand" <[EMAIL PROTECTED]> wrote in message
> Hi,
> I just want a simple page that pulls the data from a database (got that
> working fine, no problem),
> and on that page I want to be able to have an option to delete entries. I
> have tried what seems
> to be the simplest method - using a form text field, enter the appropriate
> info, and hit the submit
> button. It should then be deleted from the database. I can delete from the
> database on the
> command line, but getting it to work in php is another story. I keep
> getting 'not a valid mysql
> result resource' errors. I have 3 php/mysql books and cannot get this to
> work. I know it can't be
> as difficult as it appears.
> My goal is simple enough - I have a database that is populated from online
> web forms. It contains
> enduser names, addresses & email addresses. I made a form that the
> marketing people can use
> to view the database, search it and display it in various ways. I also
> them a form that will
> allow them to manually add enduser info into the database. That all works
> fine. It's just the doggone
> delete stuff that I just haven't got a handle on yet.
> Is there a tutorial somewhere that shows the simplest method of setting
> this up? That's all I need,
> a reference to a location for a tutorial or info on this particular
> subject.
> Thanks,
> Chip

PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to