Hello,
I got this code:

<?php
    //mysql connection
    $dbconn = mysql_connect("localhost","root","password") or die();
    mysql_select_db("imaccs_v1") or die();
    $sqlquery = "SELECT * FROM clerks"; // query on table
    $sqlresult = mysql_query($sqlquery, $dbconn);
    $count = mysql_num_rows($sqlresult); // count query result
    ?>
    <table width="400" border="1" cellspacing="1" cellpadding="0">
    <tr><td>  <form method="post" action="delete5.php">
    <table width="400" border="1" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"><tr>
    <td bgcolor="#FFFFFF"> </td>
    <td colspan="4" bgcolor="#FFFFFF"><strong>Delete multiple rows in mysql</strong> </td></tr>
    <tr><td align="center" bgcolor="#FFFFFF">#</td>
    <td align="center" bgcolor="#FFFFFF"><strong>Id</strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>Name</strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>Lastname</strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>Email</strong></td></tr>
    <?php while($rows = mysql_fetch_assoc($sqlresult)){ ?>
    <tr><td align="center" bgcolor="#FFFFFF">
    <input type="checkbox" name="checkbox[]" id="checkbox[]" value="<?php echo $row['id']?>" />
    </td><td bgcolor="#FFFFFF"><?php echo $rows['id']; ?></td>
    <td bgcolor="#FFFFFF"><?php echo $rows['fname']; ?></td><td bgcolor="#FFFFFF"><?php echo $rows

['lname']; ?>
    </td><td bgcolor="#FFFFFF"><?php echo $rows['email']; ?>
    </td></tr>
    <?php } ?>
    <tr><td colspan="5" align="center" bgcolor="#FFFFFF">
    <input name="delete" type="submit" id="delete" value="Delete"></td></tr>
    <?php
    //mysql connection here
    if($_POST['delete']) // from button name="delete"
    {
    $checkbox = $_POST['checkbox']; //from name="checkbox[]"
    $countCheck = count($_POST['checkbox']);
    for($i=0;$i<$countCheck;$i++)
    {
    $del_id = $checkbox[$i];
    $sql = "delete from test_mysql where id = $del_id";
    $result = mysql_query($sql, $dbconn);
    }
    if($result)
    {
    echo "successful delete";
    }
    else
    {
    echo "Error: ".mysql_error();
    }
    }
    ?></table>
    </form></td></tr></table>


    Problem: Undefined index: delete in delete.php on line 31
Someone help me solve it.

Recommended Answers

All 2 Replies

It is a notice. This is not a serious warning. It just tells you that you are using a variable that has not been defined yet.

Two possible fixes:
1. Turn off the reporting of notices (e.g. error_reporting(E_ALL & ~E_NOTICE); on the first line of your first script).
2. Instead of using if ($_POST['delete']), use if (!empty($_POST['delete'])).

You submit: ->

if(isset($_POST['delete')) {
I see only one )

Hope I'm rigth!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.