Forum Moderators: coopster
as in,
$contact_name = $_POST["contact_name"]; //contact_name was passed as a hidden form field when this file was targeted
$query = "DELETE FROM table_name WHERE Name='$contact_name'";
$result = mysqli_query($con,$query);
if(!$result)
{
die('error deleting from the database:' . mysqli_error());
}
else echo " 1 contact deleted";
I am using the above code and nothing is happening. Is the syntax for the bold part correct ?>
Are you certain the form element name is "contact_name"? If you view the HTML source, is there a value for that element?
Does the `Name` field exist in the database? Or is it `name`?
Does the value you're passing to the script in the POST element exist? i.e. you type "Bob", and there is a record with a `Name` field value of "Bob"?
Something else to consider if that form is public; I can create a script to automatically test against a rainbow table of names, POSTing to your server as much as I like and trying to destroy all records in your database. The same thing could be said for a numeric index form - heck, I'd start at 0 and go to 100000 in no time! Hopefully this is in a protected admin section somewhere.
Here is the scenario
I have a page that displays data from a MySQL table into HTML table using a while loop..
The last column of the HTML table contains a delete button.. ie each row has a delete button to delete that particular record..
here the hidden form field is passed as follows
echo "<td><form action=....> <input type='submit'.../> <input type='hidden' name='contact_name' value='<?php echo $row[Name]; ?>'</form> </td>";
this form targets a page that asks for confirmation
On confirm page there are two form fields - yes button to delete and cancel button to return to homepage (which is working properly)
The yes button targets delete.php and it opens a page.. the css and everything is loaded but the record is not deleted..no error is displayed..
At the same time I am also passing user variable selected from a drop down list on the very first page as a hidden form field.. as in $_POST["user"] in all the subsequent pages..
There is a diffeent table for each user and in delete.php, if and else if statements are used to work with specific user tables
if($_POST["user"]=='knownuser')
{
}
else if ($_POST["user"]=='knownuser2')
{
}
I know its all messed up... thanks for bearing with me
[edited by: naiquevin at 2:27 pm (utc) on Mar. 12, 2009]
this form targets a page that asks for confirmation
Wait..what? You have this form target an intermediate script? Well then the POST values are lost, unless you're using a session. As soon as you POST to the intermediary script, the value is gone.
You can confirm this by placing this code at the top of each receiving script:
print_r($_POST);
Additionally, make sure you look at the actual HTML source in your browser, not the HTML in your PHP script.
And how can I show a warning message in a dialogue box and eliminate the intermediate confirmation page /? Can it be done using PHP?