how to delete record from the database using checkbox

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
User avatar
nehrav
Forum Commoner
Posts: 38
Joined: Sun Sep 20, 2009 6:55 am
Location: New Delhi
Contact:

how to delete record from the database using checkbox

Post 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:
Attachments
Prodcuts from database repeated with loop
Prodcuts from database repeated with loop
test.jpg (20.6 KiB) Viewed 397 times
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: how to delete record from the database using checkbox

Post 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.
User avatar
nehrav
Forum Commoner
Posts: 38
Joined: Sun Sep 20, 2009 6:55 am
Location: New Delhi
Contact:

Re: how to delete record from the database using checkbox

Post 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:
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: how to delete record from the database using checkbox

Post 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 ;)
Post Reply