tags:

views:

61

answers:

1

I want the work of the Control Panel in my site for members ...

I designed the page is displayed all the registered members on my site

And i but it checkbox front each member name ,becuase it allowed to select multiple name then click delete button The following code works

but now i want confirm alert before delete code working

even , if clicked on ok the deletion is working , and if clicked on cancel the is not working ..

how i can work it ?

<?php
while($row = mysql_fetch_array($sql1))
{
?>
  <tr>
      <td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $row['MemberID']; ?>"></td>
      <td bgcolor="#FFFFFF"><?php echo $row['MemberName']; ; ?></td>
  </tr>

<?php
}

?>

<tr>
    <td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="delete"  onclick="javascript:return confirm('are you sure to delete this record???? ')"/></td>
</tr>

<?php

$delete = $_REQUEST['delete'];
$checkbox = $_REQUEST['checkbox'];
$count = count($_REQUEST['checkbox']);

// Check if delete button active, start this
if($delete) {

    echo "<script language=\"Javascript\">\n";
    for($i=0;$i<$count;$i++){
        $del_id = $checkbox[$i];


        $sql = "Delete  FROM members where MemberID ='$del_id'";

        $sq2 = "Delete FROM joinroom where  MemberID ='$del_id'";

        $result1 = mysql_query($sql);
        $result2 = mysql_query($sq2);

        echo "else {\n";
        echo "alert ('Nothing deleted');\n }";
        echo "</script>";
    }
}
?>

Thanks a lot.........

+1  A: 

PHP and Javascript doesn't run in sync as you seem to think. PHP runs at the server side, produces a bunch of template text with embedded HTML/CSS/JS, sends it over network from server to client side using HTTP protocol. Once arrived at client side, the JS starts to get interpreted and executed. Rightclick page in your webbrowser and do View Source. It'll become more clear. You'll see a good JS syntax error.

By the way, sanitize your inputs. This is a good SQL injection hole.

BalusC
Is not clear to me your idea as required .... Which I understood from your speech that it is difficult to do so????Do not they?
I hope your help me ...I am not experienced enough Tell me where the error even I modified it to you that I tested the code he's working, but if you click on the button twice for two successive (I mean that if you specifically and then clicking on button and you choose ok the first time, but if you have the same work is again ........ it works, it is perplexing indeed
Open page in webbrowser, execute the delete, rightclick page and choose *View Source*, head to the `<script>` which you generated with PHP. Does it look valid? Does the `else{` belong there? Fix it accordingly.
BalusC
Please ..... How do I make this script work properly, so ask me before the deletionTo date, I could not reach the correct solution......