0

can't delete records..
here's the codes..

<?php


mysql_connect('localhost','root','');

mysql_select_db('records');

 

?>

<?php


if(isset($_GET['btndelete'])){

$position = $_GET['position'];

if(isset($position)){

foreach($position as $val){

mysql_query( "DELETE FROM positions WHERE id='".$val."'" );

}
}

}


?>
<html>

      <head>

      <tittle>

      confirm

      </title>

      <script>

  function deleterec(){

      if(confirm("Are you sure you want to delete?")){  

     return true;

      }else{

      return false;

      }

      }

     </script>

      </head>

      <body>

      <form name='frm' method='get' onsubmit='return deleterec()'>

      <table border='1'>



      <?php
         mysql_connect('localhost','root');
  
      mysql_select_db('records');

      $result = mysql_query("SELECT * FROM positions") 
        or die(mysql_error());
      while($row = mysql_fetch_array( $result )) {
        
        

        echo '<td><center><td>'<input type='checkbox' name='position' >'</tr></td>'. $row['position'] . '</td>';
      }
      echo "</table>";
     ?>



      <input type='submit' name='btndelete' value='delete' />

      </form>

      </body>

      </html>
3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by vaultdweller123
1

Have you ever tried to echo the results of $position and $val as $position determines $val and $val accounts for an id value which in turn accounts for what is to be deleted, it's good to know if the chain is broken. By the way, you should let 'HTML deal with HTML and PHP deal with PHP'. Maybe you can change your code on lines 39-53 to:

<?php
      mysql_connect('localhost','root');
      mysql_select_db('records');

      $result = mysql_query("SELECT * FROM positions") 
      or die(mysql_error());
      while($row = mysql_fetch_array( $result )) {
        
      ?>

        <tr><td>
<input type="checkbox" name="position" value="<?php  echo $row['position']; ?>" />
</td></tr>
     <?php }?>
     </table>

Why the use of the get method, do you really need the values sent to the url? Unless you are going to use those values for other purposes, you don't want to be spreading data where not necessary. $_POST method works just fine I believe.

Edited by CJesusSaves: n/a

Votes + Comments
Correct.
0

hey takeshi
just change line 50
from

echo '<td><center><td>'<input type='checkbox' name='position' >'</tr></td>'. $row['position'] . '</td>';

to

echo "<td><center><td><input type='checkbox' name='position[]' value='".$row['id']."' ></tr></td>". $row['position'] . "</td>";

the problem there is you forgot to set name to an array, position[], and try to use qoutes properly.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.