keymasterviriya1150

formdel

Apr 14th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.20 KB | None | 0 0
  1. <html>
  2. <head><title>Delete a Row</title></head>
  3. <script language="JavaScript">
  4. function confirmDelete(){
  5.     return confirm('Are you sure you want to delete this?');
  6. }
  7. </script>
  8. <body>
  9. <?php
  10.  
  11. $connect = mysqli_connect("localhost","root","","class");
  12. if(!isset($smtDelete)){
  13.     $sql ='select * from student';
  14.     $result = mysqli_query($connect,$sql);
  15.     $numrows = mysqli_num_rows($result);
  16.     $numfields = mysqli_num_fields($result);
  17.  
  18.     if(!$result){
  19.         echo '<b>Error</b>'.mysqli_error().'<br>';
  20.     }
  21.     elseif($numrows==0){
  22.         echo '<b>Quary executed successfully but no row returns!</b>';
  23.     }
  24.     else{
  25.         echo '<table border="1" cellspacing="0" cellpadding="3">';
  26.         while($row = mysqli_fetch_array($result)){
  27.             echo '<form name="frmDelete'.$row['StudentID'].'" method="post" action="delete.php">'."\n";
  28.             echo '<tr>';
  29.             for($i=0;$i<$numfields;$i++){
  30.                 echo '<td>'.$row[$i].'&nbsp;</td>'."\n";
  31.             }
  32.             echo '<input type="hidden" name="id" value="'.$row['StudentID'].'">'."\n";
  33.             echo '<td><input name="smtDelete" type="submit" value="Delete" onClick="return confirmDelete();"></td>'."\n";
  34.             echo '</tr>'."\n";
  35.             echo '</form>'."\n";
  36.         }
  37.         echo '</table>';
  38.     }
  39. }
  40. mysqli_close($connect);
  41. ?>
  42. </body>
  43. </html>
Add Comment
Please, Sign In to add comment