php - Rows are not being deleted -


here php code select , delete rows form table:

    <h1>deleting multiple records using php &amp; mysql</h1>      <p>&nbsp;</p>      <?php 

these db connection:

  $host = "localhost"; // host name  $username = "root"; // mysql username  $password = ""; // mysql password  $db_name = "project"; // changed database name  $tbl_name = "users";  mysql_connect($host, $username, $password) or die("cannot connect");  mysql_select_db($db_name) or die("cannot select db");  $sql = "select * $tbl_name";  $result = mysql_query($sql);  $count = mysql_num_rows($result); ?> 

here html code retrieve data database:

   <table width="400" border="0" cellspacing="1" cellpadding="0">   <tr><td><form name="form1" method="post" action="">         <table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#cccccc"><tr>             <td bgcolor="#ffffff">&nbsp;</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>first name</strong></td>             <td align="center" bgcolor="#ffffff"><strong>last name</strong></td>             <td align="center" bgcolor="#ffffff"><strong>gender</strong></td>             <td align="center" bgcolor="#ffffff"><strong>phone number</strong></td>             <td align="center" bgcolor="#ffffff"><strong>experiance</strong></td>             <td align="center" bgcolor="#ffffff"><strong>user name</strong></td>             <td align="center" bgcolor="#ffffff"><strong>password</strong></td>             </tr>             <?php while ($rows = mysql_fetch_array($result, mysql_assoc)) { ?>                  <tr>                 <td align="center" bgcolor="#ffffff">                     <input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['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['gend']; ?>    </td>                 <td bgcolor="#ffffff"><?php echo $rows['phone']; ?>    </td>                 <td bgcolor="#ffffff"><?php echo $rows['exp']; ?>    </td>                 <td bgcolor="#ffffff"><?php echo $rows['uname']; ?>    </td>                 <td bgcolor="#ffffff"><?php echo $rows['pwd']; ?>    </td>                 </tr>             <?php } ?>             <tr><td colspan="5" align="center" bgcolor="#ffffff">                 <input name="delete" type="submit" id="delete" value="delete" onclick="javascript:confirm('are sure delete')"></td></tr>             <?php             if(isset($_post['delete'])){                 $checkbox = $_post['checkbox'];               for($i=0;$i<count($_post['checkbox']);$i++){            $del_id = $checkbox[$i];             $sql = "delete $tbl_name id='$del_id'";              print $sql;              $result = mysql_query($sql);}                 if($result){echo "<meta http-equiv=\"refresh\" content=\"0;url=index.php\">";}}      mysql_close();     ?>     </table></form></td></tr></table>      <p>record count: <?php echo number_format($count) ?></p>*/ 

i tried many times not deleting single row table. changed code of executing query....please check , inform me...

in code

if (isset($_post['checkbox']) && count($_post['checkbox']) > 0) {      $deleteids = $_post['checkbox'];   // array      $sql = "delete users id in (" . implode(",", $deleteids) . ") ";      // run query  } 

we need see actual code trying "delete". the usual mysql_query($sql) won't work. have use mysql_exec() instead of mysql_query().

update: sorry, confusing form of query. mysql_query("delete table (whatever)") should work, though returns true on success or false on failure, not rowset.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -