Jump to content

problem deleting particular row record


vinpkl

Recommended Posts

hi all

 

I m working in admin section.

There i have order details rows. i have a option of deleting the record on clicking the delete button with each row.

Everytime when i click delete button it deletes the record that is on no.1 not the particular record that i selected. whether i select the delete button at row 5 then also it deletes the record of row 1.

 

this the code

<?php
if(isset($_REQUEST['del_item_x']))
{
$qry_del="select * from order_detail_table";
$result_del=mysql_query($qry_del);
$row_del=mysql_fetch_array($result_del);
$order_id=$row_del['order_id'];
$product_name=$row_del['product_name'];
//echo "test". $row_del['order_id'];
$qry_del="DELETE from order_detail_table where product_name='$product_name'";
echo $qry_del;
if(mysql_query($qry_del))
{
$msg="item deleted success";
}
else
{
$msg="item not deleted";
}
}
?>

 

vineet

Link to comment
Share on other sites

hi golden eye

 

i tried using order_id inside the qry

this is the code

<?php
if(isset($_REQUEST['del_item_x']))
{
$qry_del="select * from order_detail_table";
$result_del=mysql_query($qry_del);
$row_del=mysql_fetch_array($result_del);
$order_id=$row_del['order_id'];
$product_name=$row_del['product_name'];
//echo "test". $row_del['order_id'];
$qry_del="DELETE from order_detail_table where order_id='$order_id' AND product_name='$product_name'";
echo $qry_del;
if(mysql_query($qry_del))
{
$msg="item deleted success";
}
else
{
$msg="item not deleted";
}
}
?>

 

Like i have product name nokia on no.1 and samsung on no.2.

when i echo the result after clicking delete button on samsung i get

<?php
DELETE from order_detail_table where order_id='67' AND product_name='nokia' 
?>

 

vineet

 

Link to comment
Share on other sites

Here's the delete from table that I have in one of my scripts:

 

while ($row = mysql_fetch_array($result)) {
   $jobid = $row['id'];
   $jobtitle = $row['title'];
   $added = $row['added'];
   $empl = $row['employer'];
   echo '<p>' . $jobtitle . ", " . $empl . ": " . $added .
       ' <a href="' . $_SERVER['PHP_SELF'] .
       '?deletejob=' . $jobid . '">' .
       'Delete this job</a></p>';}
}


// If a job has been deleted,
// remove it from the database.
if (isset($_GET['deletejob'])) {
   $jobid = $_GET['deletejob'];
   $sql = "DELETE FROM jobs WHERE id=$jobid";
   if (@mysql_query($sql)) {

     echo "<b>Job Deleted!<br>You'll be redirected to Home Page after (4) Seconds";
     #header("location: deleted.php");
     echo "<meta http-equiv=Refresh content=4;url=".$_SERVER['PHP_SELF'].">";
#     $_SERVER['PHP_SELF'];

 

Edit it as you need.

Link to comment
Share on other sites

hi gmcalp

 

thanks for reply.

 

The problem is that when i need to delete all products of one id in single click then it works fine. The delete button deletes all products of same id.

 

I need to delete the particular item of that id. here i am facing trouble.

 

vineet

 

Here's the delete from table that I have in one of my scripts:

 

while ($row = mysql_fetch_array($result)) {
   $jobid = $row['id'];
   $jobtitle = $row['title'];
   $added = $row['added'];
   $empl = $row['employer'];
   echo '<p>' . $jobtitle . ", " . $empl . ": " . $added .
       ' <a href="' . $_SERVER['PHP_SELF'] .
       '?deletejob=' . $jobid . '">' .
       'Delete this job</a></p>';}
}


// If a job has been deleted,
// remove it from the database.
if (isset($_GET['deletejob'])) {
   $jobid = $_GET['deletejob'];
   $sql = "DELETE FROM jobs WHERE id=$jobid";
   if (@mysql_query($sql)) {

     echo "<b>Job Deleted!<br>You'll be redirected to Home Page after (4) Seconds";
     #header("location: deleted.php");
     echo "<meta http-equiv=Refresh content=4;url=".$_SERVER['PHP_SELF'].">";
#     $_SERVER['PHP_SELF'];

 

Edit it as you need.

Link to comment
Share on other sites

ur code seems to produce single result since u have not used loop 
while($row_del=mysql_fetch_array($result_del))
{
$qry_del="DELETE from order_detail_table where order_id='$order_id' AND product_name='$product_name'";
echo $qry_del;

}

 

hi zenag

 

i tried putting while loop. but it gaves me same result. it also deletes the product at no.1 not the particular product selected.

 

<?php
if(isset($_REQUEST['del_item_x']))
{
$qry_del="select * from order_detail_table";
$result_del=mysql_query($qry_del);
$row_del=mysql_fetch_array($result_del);
$order_id=$row_del['order_id'];
$product_name=$row_del['product_name'];
//echo "test". $row_del['order_id'];
while($row_del=mysql_fetch_array($result_del))
{
$qry_del="DELETE from order_detail_table where order_id='$order_id' AND product_name='$product_name'";
echo $qry_del;
}
//echo $qry_del;
if(mysql_query($qry_del))
{
$msg="item deleted success";
}
else
{
$msg="item not deleted";
}
}
?>

 

vineet

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.