deleting multiple rows from database in php

this is the code that i have wrote for deleting multiple rows from database. but on pressing delete button instead of deleting a selected row it comes back to the same page again.. so i want someone to correct my code or give me the rite code for deletion. thank you



// Check if delete button active, start this
if($delete)
{
for($i=0;$i<$count;$i++)
{
$del_id = $checkbox[$i];
$sql = "DELETE FROM $tbl_name WHERE id='$del_id'";
$result = mysql_query($sql);
}

// if successful redirect to delete_multiple.php
if($result)
{
echo "";
}
}
mysql_close();
?>

Replies

  • Manish Goyal
    Manish Goyal
    can you post complete file here?
  • manojsinghrana
    manojsinghrana
    here is the complete file.


    $host="localhost"; // Host name
    $username="root"; // Mysql username
    $password=""; // Mysql password
    $db_name="test"; // Database name
    $tbl_name="test_mysql"; // Table name

    // Connect to server and select databse.
    mysql_connect("localhost", "root", "")or die("cannot connect");
    mysql_select_db("test")or die("cannot select DB");

    $sql="SELECT * FROM $tbl_name";
    $result=mysql_query($sql);

    $count=mysql_num_rows($result);

    ?>

















    while($rows=mysql_fetch_array($result)){
    ?>







    }
    ?>



    // Check if delete button active, start this
    if($_POST['delete']){
    for($i=0;$i<$count;$i++){
    $del_id = $checkbox[$i];
    $sql = "DELETE FROM $tbl_name WHERE id='$del_id'";
    $result = mysql_query($sql);
    }

    // if successful redirect to delete_multiple.php
    if($result){
    echo "";
    }
    }
    mysql_close();
    ?>
      Delete multiple rows in mysql
    # Id Name Lastname Email


  • Manish Goyal
    Manish Goyal
    hey check this code ,it works

    Modify it according to your requirement

    Please post your code in code tags next time thanks

    
    
    $value) { $sql="Delete from chandigarh where id='$value'"; $final=mysql_query($sql); if($final) { echo ""; } } } } // Check if delete button active, start this // if successful redirect to delete_multiple.php mysql_close(); ?>
      [b]Delete multiple rows in mysql[/b]
    # [b]Id[/b] [b]Area ID[/b] [b]Name[/b]
  • Manish Goyal
    Manish Goyal
    hey check this code ,it works

    Modify it according to your requirement

    Please post your code in code tags next time thanks

    
    
    $value) { $sql="Delete from chandigarh where id='$value'"; $final=mysql_query($sql); if($final) { echo ""; } } } } // Check if delete button active, start this // if successful redirect to delete_multiple.php mysql_close(); ?>
      [b]Delete multiple rows in mysql[/b]
    # [b]Id[/b] [b]Area ID[/b] [b]Name[/b]
  • Saandeep Sreerambatla
    Saandeep Sreerambatla
    I have checked the link and its not an advertisement.
    But please refrain from posting links , answer in your own words. If not explain what you learn. It doesnt help pasting links from google.

    If CE is accessible so is google for everyone.

You are reading an archived discussion.

Related Posts

gaffe (g): A social blunder; an embarrassing mistake; a faux pas In some cultures, burping after you eat is considered a sign that you liked the meal, in Western culture,...
If xyz is not equal to 0 and x percent of y percent of z is t, then z = A) 100t/xy B) 1,000t /xy C)10,000t/xy D) xy/10,000t E) 10,000xy/t
If r=1+1/3+1/9+1/27 and s=1+r/3, then s exceeds r by A)1/3 B)1/6 C) 1/9 D) 1/27 E) 1/81
foreach($delete as $key =>$value) i am not able to get this code. can someone please tell me what this piece of code actually do. Thank you
New > Check Your Mobile Quality! Press the following on your mobile *#06# and the-international mobile equipment identity number appears. Then check the 7th and 8th numbers: -------------------- 1 2...