PHP 清空 MySql 指定数据表中的所有数据
发布时间:2020-12-13 20:25:00 所属栏目:PHP教程 来源:网络整理
导读:PHP 清空 MySql 指定数据表中的所有数据,在小编在网上闲逛时,这是某技术博客的一篇文章,说是文章,并没有文字,只有代码,经过测试可以使用,现在分享给大家。 共有三个文件,其实也可以合并写成一个。 1.conn.php: Copy to Clipboard 引用的内容: [www
PHP 清空 MySql 指定数据表中的所有数据,在小编在网上闲逛时,这是某技术博客的一篇文章,说是文章,并没有文字,只有代码,经过测试可以使用,现在分享给大家。 共有三个文件,其实也可以合并写成一个。 1.conn.php: Copy to Clipboard <?php $id=mysql_connect("localhost","root","mysql") or die('连接失败:' . mysql_error()); if(mysql_select_db("phpjcdb",$id)) //说明:phpjcdb 是数据库名称 echo ""; else echo ('数据库选择失败:' . mysql_error()); mysql_query("set names gb2312"); //设置为简体中文 ?> 2.index.php: Copy to Clipboard <?php include("conn.php"); ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>清空指定数据表中的所有数据</title> <style type="text/css"> <!-- .STYLE2 {font-size: 13px} .STYLE3 {font-size: 12px} --> </style> </head> <script language="javascript" type="text/javascript"> function deletes(){ if (window.confirm('确定要删除该记录??')==true){ return true; }else{ return false;} } </script> <body> <form action="index.php" method="post" name="form1" id="form1"> <table width="614" height="90" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="20" height="53"> </td> <td width="219"> </td> <td width="355"> </td> <td> </td> </tr> <tr> <td height="26"> </td> <td align="right"><select name="select"> <?php $result = mysql_list_tables ("db_database06"); $i = 0; while ($i < mysql_num_rows ($result)) { $tb_names = mysql_tablename ($result,$i); ?> <option value="<?php echo $tb_names;?>"><?php echo $tb_names;?></option> <?php $i++; }?> </select> </td> <td><input type="submit" name="Submit2" value="提交" /></td> <td width="20"> </td> </tr> <tr> <td height="5"> </td> <td align="right"> </td> <td> </td> <td> </td> </tr> </table> <table width="614" height="25" border="0" cellpadding="0" cellspacing="0" background="images/bg03.jpg"> <tr> <td width="20"> </td> <td width="569"> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <?php if($_POST['Submit2']=="提交"){ $select = $_POST['select']; $query1=mysql_query("select * from $select"); $query2=mysql_query("select * from $select"); $myrow=mysql_fetch_row($query2);?> <tr> <?php for($i=0;$i<count($myrow);$i++){?> <td align="center"> <span class="STYLE2"> <?php echo mysql_field_name($query2,$i);?></span></td> <?php } ?> </tr> <?php while($myrow=mysql_fetch_row($query1)){ ?> <tr> <?php for($i=0;$i<count($myrow);$i++){?> <td align="center"><span class="STYLE3"> <?php echo $myrow[$i];?></span></td> <?php } ?> </tr> <?php } } ?> </table></td> <td width="20"> </td> </tr> </table> </form> <form action="index_ok.php?lmbs=<?php echo $select;?>" method="post" name="form2" id="form2" onSubmit="return deletes();"> <table width="614" height="28" border="0" cellpadding="0" cellspacing="0"> <tr> <td align="center"><input type="submit" name="Submit" value="删除数据"></td> </tr> </table> </form> </body> </html> 3.index_ok.php: Copy to Clipboard <?php session_start(); include("conn.php"); if($_POST['Submit']==true){ $lmbs = $_GET['lmbs']; $result=mysql_query("delete from $lmbs"); if($result==true){echo "删除成功!";}else{echo "删除失败!!";} } ?> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |