Posted by Steve Belanger on 03/11/07 19:27
first i would put your HTML piece inside a FORM tag and speficy it to go as
POST, and from there use the fields to perform the delete. like in the
following example
<form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
<p>Which record would you like to delete?</p>
<P>Enter Record #<br>
<input type=text name="id" size=20>
<input type=submit name="submit" value="Delete Record">
</form>
This form would basically reload the same page but pass the FORM information
to it, and form there in your SQL query you would use something like that:
if (!empty($_POST))
{
mysql_query("DELETE FROM testtable WHERE id='{$_POST['id']}'");
}
i enclosed it within an IF statement so that it does not get called if the
$_POST array is empty. Eventually you would want to add more validation such
as checking the referrer page to ensure that the delete request came from
this page only (and not from another domain who might want to try to hijack
your form)
Hope this helps.
Steve.
"Mr. Newt" <lektrikpuke@_yahoo.com> wrote in message
news:EICdnVlmxetj3GnYnZ2dnUVZ_qunnZ2d@comcast.com...
> <?php
> //db & table names used to connect
> include ("connect.php");
> //display a list of names preceeded by id #
> include ("display_names.php");
> ?>
> <p>Which record would you like to delete?</p>
> <P>Enter Record #<br>
> <input type=text name="id" size=20>
> <input type=submit name="submit" value="Delete Record">
> <?php
> mysql_query("DELETE FROM testtable WHERE id=$id");
> ?>
>
> The above deletes the last record in the table. Obviously it's not
> getting
> the # that is being entered. Any help?
>
> Thanks.
>
> Robert
>
>
[Back to original message]
|