English 中文(简体)
删除多个 MySQL与PHP的超链接记录
原标题:Deleting multiple MySQL records from a hyperlink with PHP

我试图用检查箱删除多个记录。 我把每个检查箱装上记录索引:

<?php $row_count = 1; do {  ?>
    <tr <?php if ($row_count%2) { ?>bgcolor="#F4F4F4"<?php } ?>>
      <td align="center" ><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $row_contactlist[ contact_id ]; ?>"></td>
      <td align="center" ><p><?php echo $row_contactlist[ contact_id ];?></p></td>
    </tr>
    <?php $row_count++; } while ($row_contactlist = mysql_fetch_assoc($contactlist)); ?>

使用以下链条删除:

<a class="addcontact" href="delete.php?mContact=<?php for($i=0;$i<=$row_count;$i++) { $del_id = $checkbox[$i]; } echo $del_id ?>" style="border-bottom:0px" >Delete Contact(s)</a>  

删除。 php

if (isset($_GET[ mContact ])) {
mysql_query("DELETE FROM contacts WHERE contact_id = ".$_GET[ mContact ]."");
mysql_query("DELETE FROM history WHERE history_contact = ".$_GET[ mContact ]."");
mysql_query("DELETE FROM notes WHERE note_contact = ".$_GET[ mContact ]."");
redirect( You have deleted some contacts ,"contacts.php");
}

间接工程,即与你接触的网页重载,已经删除了某些接触,它像我一样没有错误,但没有任何接触被删除。

UPDATE: Thanks guys very speedy response. Total newb to PHP so everything is massively appreciated.

因此,我用的是一笔总账,而不是一个超级链接:

<td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td>
最佳回答

我认为,你在选择应予删除的标准方面进行了组合。

用户与删除网页的联系与代码中的核对箱无关。

我认为,你们想要做的是:

  1. Create the checkboxes (and if you want something to be deleted by default, set checked="checked"
  2. Change the <a href..> to a submit button
  3. In the delete.php the checkboxes will be in an array $_GET[ checkboxes ], which you can iterate through

NOW, onto the issues that @JohnP alluded to:

  1. This is pretty insecure way to do this unless you have removed all your validation code before posting here.
  2. I would recommend passing everything by $_POST for a little bit more security through obscurity
  3. Check that the user has the privileges to delete the rows that they are attempting to delete.
  4. Set a LIMIT 1 on each delete (or update) query so you don t accidentally delete all the rows in your database.

<>>>>>

如果您希望有一个单一的删除链接,则需要在<代码>do......while路段内添加这一链接。 看来,在座右边外有链接,你通过一切结果,将其全部添加到<条码>。 您的手稿没有限定人,就没有把这些信息区分开来。

问题回答

不要将标题移至别处,而是评论你的后向功能,允许其在填写<条码>后留在网页上。 参看其中报告的任何错误(如果display_errors = on in php.ini)。 您的错误记录是否报告了错误?

而且,我肯定是说......的。 页: 1 这极易受到卡片注射袭击。 您必须核实,这是一种分类,或贵国记录的任何数据类型:<代码>contact_id。

此外,利用超级链接删除数据库中未经确认页面的记录是不明智的。 这一页是否被索引人rawl弄? 索引员将击中删除链接和删除原因。 更可取的方法是使用一种形式,并附有提交纽伦以供删除。

为什么你不将外国钥匙列入<代码>history_contact和注_contact 查询contact_id with CASCADE DELETE?

这样,如果你删除联系,我的孩子们就将照顾你们。

(如前几个员额所示,验证你对卡片注入的数据投入!)





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签