Home  >  Article  >  Backend Development  >  PHP 在table中删除一条记录

PHP 在table中删除一条记录

WBOY
WBOYOriginal
2016-06-23 14:23:281295browse

PHP在table中删除一条记录

各位好,初次接触PHP弱弱的文革问题,

我想点击删除按钮的时候删除一条记录。如下图

下面把代码贴出来,

<script language="javascript" >	function Delete11(var id)	{	           .................	}</script><form action="delete.php" method = "post">	<table border = "1" cellpadding = "3" align = "center">	 <tr> 	 	<th>编号</th>        <th>商品名称</th>         <th>商品货号</th>         <th>商品价格</th>        <th>促销价</th>        <th>操作</th>    </tr> 	<?php 		include ('..\Conn\ConnectionDB.php');			$sql = "select *from products";			$result = mysql_query($sql);			$row = mysql_fetch_row($result);			while ($row){	?>						<tr>				<td><?php echo $row[0]?></td>				<td><?php echo $row[3]?></td>				<td><?php echo $row[2]?></td>				<td><?php echo $row[11]?></td>				<td><?php echo $row[12]?></td>				<td><button  onclick = Delete11(<?php echo $row[0]?>)>删除</button></td>			</tr>	 <?php        	$row = mysql_fetch_row($result);}       ?>	</table></form>


用JS怎么实现啊,还有如果不用JS怎么把我要删除记录的ID传到delete.php处理

回复讨论(解决方案)

不用 js

'>删除

使用 js


function Delete11(id) {
  location = 'delete.php?id='+id;
}

不用 js

'>删除

使用 js


function Delete11(id) {
  location = 'delete.php?id='+id;
}
xu版真是无处不在啊

通过js传递主键id到服务端,服务端接收参数执行sql delete * from table where id =?即可。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn