Page 1 of 1

how to delete record from the database using checkbox

Posted: Sat Oct 03, 2009 6:22 am
by nehrav
Hi frndz,

Please check the attached image first... :crazy:

There you will find a list of products with their details. I want to delete the selected product (checked with checkbox).

I know, I will be successful if I manage to give the prod_id on the click of delete.

But on adding prod_id , it give me the error :drunk:

Notice: Undefined variable: prod_id in C:\wamp\www\test\edit.php on line 55 :banghead:

My code is

[ php]
<?php

$con = mysql_connect("localhost","XXX","XXXXXXXXX");
$db = mysql_select_db("test",$con);

$select = mysql_query("select * from test_data");

echo "<table border='0' cellpadding='4' cellspacing='0' align='center' width='96%'>
<tr bgcolor='#24a1b6' class='whitetext'>
<td>&nbsp;</td>
<td>Name</td>
<td>Code</td>
<td>Type</td>
<td>Hotel Location</td>
</tr>";

while($result = mysql_fetch_array($select))
{
$prod_name = $result['prod_name'];
$prod_Code = $result['prod_Code'];
$prod_type = $result['prod_type'];
$prod_location = $result['prod_location'];

echo "<tr class='black'>
<td><input class='none' value='prod_id' name='prod_id' type='checkbox'></td>
<td>$prod_name</td>
<td>$prod_Code</td>
<td>$prod_type</td>
<td>$prod_location</td>
<td align='center'><A href='delete.php?prod_id=$prod_id' class='black'>DELETE</A></td>
<td align='right'><A href='update.php' class='black'>UPDATE</A></td>
</tr>";

}
echo "</table>";
?>
[ /php]


Pleaseeee, help me...... :cry:

Re: how to delete record from the database using checkbox

Posted: Sat Oct 03, 2009 1:31 pm
by John Cartwright
You forgot to define $prod_id when iterating the result set..

Code: Select all

$prod_name = $result['prod_name'];
$prod_Code = $result['prod_Code'];
$prod_type = $result['prod_type'];
$prod_location = $result['prod_location'];
 
$prod_id = $result['prod_id']; //add me
Secondly, you better make sure this is not open to the public, you wouldn't want a search engine scraping those links.

Re: how to delete record from the database using checkbox

Posted: Mon Oct 05, 2009 7:35 am
by nehrav
John Cartwright wrote:You forgot to define $prod_id when iterating the result set..

Code: Select all

$prod_name = $result['prod_name'];
$prod_Code = $result['prod_Code'];
$prod_type = $result['prod_type'];
$prod_location = $result['prod_location'];
 
$prod_id = $result['prod_id']; //add me
Secondly, you better make sure this is not open to the public, you wouldn't want a search engine scraping those links.

Thanks for your reply John,

Can you tell me how I can post the code neatly in the forum as you write in your reply.
Secondly, how can I move/delete the post when problem gets solved.

And I try your code and its working now but earlier when I try n doing the same thing I was not successful........

but, whatever its working now........... :drunk:

Re: how to delete record from the database using checkbox

Posted: Mon Oct 05, 2009 8:23 am
by jackpf
Can you tell me how I can post the code neatly in the forum as you write in your reply.
Don't need spaces in tags ;)