Delete MySql Rows Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • imarkdesigns
    New Member
    • Jul 2007
    • 46

    Delete MySql Rows Problem

    Hello everyone.. a newbie programmer here wants to ask why is my codes for deleting rows from my databse won't work.... seems that this codes spread to the net and no one refuse to correct it...

    can someone correct this...

    [PHP] <!-- Editable Area -->
    <?php

    include ("../dbconnection/connect.php");

    $tbl_name="sche dule"; // Table name

    mysql_connect(" $host", "$username" , "$password" )or die("cannot connect");
    mysql_select_db ("$db_name") or die("cannot select DB");

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

    $count=mysql_nu m_rows($result) ;

    ?>

    <?php
    while($rows=mys ql_fetch_array( $result)){
    ?>
    <form name="form1" action="" method="post" enctype="multip art/form-data">
    <table id="alter_rows " align="center" cellpadding="0" cellspacing="0" >
    <tr>
    <td align="center" class="adminche ckbox"> <input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"> </td>
    <td class="admindat e"> <? echo $rows['date']; ?> </td>
    <td class="admintim e"> <? echo $rows['id']; ?> </td>
    <td class="admineve nts"> <? echo $rows['events']; ?> </td>
    <td class="adminven ue"> <? echo $rows['venue']; ?> </td>
    <td class="adminloc ations"> <? echo $rows['locations']; ?> </td>
    </tr>

    </table>
    <?php
    }
    ?>
    <!-- Editable Area -->
    <table cellpadding="0" cellspacing="0" >
    <tr>
    <td><input name="delete" id="delete" type="submit" value="Delete Schedule" /></td>
    </tr>
    </table>
    <?
    // Check if delete button active, start this

    //$delete = $_REQUEST['delete'];
    //
    if($delete){
    for($i=0;$i<$co unt;$i++){
    $del_id = $checkbox[$i];
    $sql = "DELETE FROM schedule WHERE id='$del_id' LIMIT 1";
    $result = mysql_query($sq l);
    }

    // if successful redirect to delete_multiple .php
    if($result){
    echo "<meta http-equiv=\"refresh \" content=\"0;URL =deleterow.php\ ">";
    }
    }
    mysql_close();
    ?>
    </form>[/PHP]

    when a DELETE button hits nothing happens...
    Last edited by mwasif; Jul 25 '07, 05:47 PM. Reason: Added CODE tags.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by imarkdesigns
    Hello everyone.. a newbie programmer here wants to ask why is my codes for deleting rows from my databse won't work.... seems that this codes spread to the net and no one refuse to correct it...

    can someone correct this...

    #-------

    <!-- Editable Area -->
    <?php

    include ("../dbconnection/connect.php");

    $tbl_name="sche dule"; // Table name

    mysql_connect(" $host", "$username" , "$password" )or die("cannot connect");
    mysql_select_db ("$db_name") or die("cannot select DB");

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

    $count=mysql_nu m_rows($result) ;

    ?>

    <?php
    while($rows=mys ql_fetch_array( $result)){
    ?>
    <form name="form1" action="" method="post" enctype="multip art/form-data">
    <table id="alter_rows " align="center" cellpadding="0" cellspacing="0" >
    <tr>
    <td align="center" class="adminche ckbox"> <input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"> </td>
    <td class="admindat e"> <? echo $rows['date']; ?> </td>
    <td class="admintim e"> <? echo $rows['id']; ?> </td>
    <td class="admineve nts"> <? echo $rows['events']; ?> </td>
    <td class="adminven ue"> <? echo $rows['venue']; ?> </td>
    <td class="adminloc ations"> <? echo $rows['locations']; ?> </td>
    </tr>

    </table>
    <?php
    }
    ?>
    <!-- Editable Area -->
    <table cellpadding="0" cellspacing="0" >
    <tr>
    <td><input name="delete" id="delete" type="submit" value="Delete Schedule" /></td>
    </tr>
    </table>
    <?
    // Check if delete button active, start this

    //$delete = $_REQUEST['delete'];
    //
    if($delete){
    for($i=0;$i<$co unt;$i++){
    $del_id = $checkbox[$i];
    $sql = "DELETE FROM schedule WHERE id='$del_id' LIMIT 1";
    $result = mysql_query($sq l);
    }

    // if successful redirect to delete_multiple .php
    if($result){
    echo "<meta http-equiv=\"refresh \" content=\"0;URL =deleterow.php\ ">";
    }
    }
    mysql_close();
    ?>
    </form>


    ------#

    when a DELETE button hits nothing happens...
    I'm going to have to copy this to the PHP forum as well.

    Comment

    • dafodil
      Contributor
      • Jul 2007
      • 389

      #3
      Originally posted by r035198x
      I'm going to have to copy this to the PHP forum as well.
      I posted on my reply on the php forum please check it....

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by dafodil
        I posted on my reply on the php forum please check it....
        And that thread is found here.

        Comment

        • imarkdesigns
          New Member
          • Jul 2007
          • 46

          #5
          thanks guys...

          and it seems working on the live site not on the localhost...???

          um, this crazy little something... haha..

          Comment

          Working...