delete options

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Alidad
Forum Commoner
Posts: 29
Joined: Thu Mar 29, 2007 12:42 pm

delete options

Post by Alidad »

hi, i'm having trouble to understand how this php works, i wrote php to give me an options whether to delete or not, please see in php code

Code: Select all

<?php
	 

if (isset($_GET['yesdelete'])) {

	
	$id_to_delete = $_GET['yesdelete'];
	
	if ($id_to_delete = $sql->query("DELETE FROM product WHERE product_id='$id_to_delete' LIMIT 1"))

	
    $pictodelete = ("product_images/$id_to_delete.jpg");
    if (file_exists($pictodelete)) {
       		    unlink($pictodelete);
    }
	header("location: product-copy-4.php"); 
    exit();
	
}
if (isset($_GET['nodelete'])) {

	
	$id_to_delete = $_GET['nodelete'];
	
 
	header("item.php?pid=' . $product_id . '"); 
    exit();
}
?>
And in body i wrote button code

<[text]td width="12%" align="center"><input type="submit" name="Delete" id="Delete" value="Delete" />
<?php '<a href="item.php?yesdelete=' . $_GET['deleteid'] . '"></a>'?>
</td>

<td width="35%"><input type="submit" name="Cancel" id="Cancel" value="Cancel" />
<?php '<a href="item.php?nodelete=' . $_GET['deleteid'] . '"> </a>'?></td>
</tr>
[/text]

But the problem is that is not sending single to php to delete it. what did i missed!

AM
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: delete options

Post by Christopher »

Why do you have form submit buttons and links with the yesdelete and nodelete parameters? It seems like the links are enough. And where does $_GET['deleteid'] get set?
(#10850)
Alidad
Forum Commoner
Posts: 29
Joined: Thu Mar 29, 2007 12:42 pm

Re: delete options

Post by Alidad »

I wrote clear code but is still not doing anything is not even deleting without any errors see code

Code: Select all

<?php
if (isset($_POST['yesdelete'])) {
//////////////////////////////////////////////////////////
// remove item from system and delete its picture
// delete from database
//////////////////////////////////////////////////////////
	
	$id_to_delete = $_GET['yesdelete'];
	if ($id_to_delete = $mysqli->query("DELETE FROM product WHERE product_id='$id_to_delete' LIMIT 1"))
/////////////////////////////////////////////////////////////
// unlink the image from server
// Remove The Pic -------------------------------------------
/////////////////////////////////////////////////////////////
	
    $pictodelete = ("../product_images/$id_to_delete.jpg");
    if (file_exists($pictodelete)) {
       		    unlink($pictodelete);
    }
	header("location: product-copy-4.php"); 
    exit();
}
?>
html code

[text] <td width="12%" align="center"><input type="submit" name="yesdelete" id="deleteid" value="Submit" />[/text]

what did i missed!

please help thanks.

AM
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: delete options

Post by Celauran »

So if a POST parameter is set, use the GET parameter of the same name? What?

Code: Select all

        if ($id_to_delete = $mysqli->query("DELETE FROM product WHERE product_id='$id_to_delete' LIMIT 1"))
This will end in tears. Don't pass unfiltered data into a query. Look at prepared statements. Look at PDO; much simpler than MySQLi.
Post Reply