suchen
Heimphp教程php手册php mysql 删除记录, url传值删除数据

本款删除数据代码是一款根据用户url地址栏传过来的参数,再去mysql数据库中执行删除操作,PHP实例代码如下:

<?php
$host = &#39;localhost&#39;;
$user_name = &#39;root&#39;;
$password = &#39;admin&#39;;
$conn = mysql_connect($host, $user_name, $password);
if (!$conn) {
    die(&#39;数据库连接失败:&#39; . mysql_error());
}
mysql_select_db(&#39;test&#39;);
$sql = &#39;select id,name,city,created_time from users&#39;;
$result = mysql_query($sql) or die("<br/>error: <b>" . mysql_error() . "</b><br/>产生问题的sql:" . $sql);
?>
<html> 
<head> 
<title>13-12.php</title> 
<script language="网页特效"> 
 
</script> 
</head> 
<center> 
 
<body> 
<table width="75%" border="0" cellpadding="0" cellspacing="1" bgcolor="#7b7b84"> 
    <tr bgcolor="#8bbcc7">  
        <td height="33"><div align="center"><strong>用户id</strong></div></td> 
        <td><div align="center"><strong>用户名称</strong></div></td> 
        <td><div align="center"><strong>来自城市</strong></div></td> 
        <td><div align="center"><strong>注册时间</strong></div></td> 
        <td><div align="center"><strong>操作</strong></div></td> 
    </tr> 
 
<?php
if ($num = mysql_num_rows($result)) {
    while ($row = mysql_fetch_array($result, mysql_assoc)) {
?>
    <tr bgcolor="#ffffff">  
        <td height="22" align="right"><?php
        echo $row[&#39;id&#39;]; & nbsp; < / td > < tdheight = "22" > & nbsp; < ? phpecho $row[&#39;name&#39;]; & nbsp; < / td > < tdheight = "22" > & nbsp; < ? phpecho $row[&#39;city&#39;]; & nbsp; < / td > < tdheight = "22" > & nbsp; < ? phpecho $row[&#39;created_time&#39;]; & nbsp; < / td > < tdheight = "22" > & nbsp; < aonclick = "javascript:if(confirm(&#39;确定要删除用户信息吗?&#39;)) return true; else return false;"href = "13-13.php?id=<?php echo $row[&#39;id&#39;]; " > 删除 < / a > & nbsp; < / td > < / tr > < ? php
    }
}
mysql_close($conn);
?>
</table> 
</body> 
</center> 
</html> 
 
<?php
if (!isset($_get[&#39;id&#39;])) {
    echo &#39;参数错误!&#39;;
    exit;
}
$id = $_get[&#39;id&#39;];
if (emptyempty($id)) {
    echo &#39;用户id不能为空!&#39;;
    exit;
}
$host = &#39;localhost&#39;;
$user_name = &#39;root&#39;;
$password = &#39;admin&#39;;
$conn = mysql_connect($host, $user_name, $password);
if (!$conn) {
    die(&#39;数据库连接失败:&#39; . mysql_error());
}
mysql_select_db(&#39;test&#39;);
//先判断是否存在该id的用户
$sql = "select * from users where id=$id";
$result = mysql_query($sql) or die("<br/>error: <b>" . mysql_error() . "</b><br/>sql:" . $sql);
if (!mysql_num_rows($result)) {
    echo &#39;用户id错误!&#39;;
    exit;
}
//删除用户数据//开源代码phprm.com
$sql = "delete from users where id=$id";
mysql_query($sql) or die("<br/>error: <b>" . mysql_error() . "</b><br/>sql:" . $sql);
mysql_close($conn);
echo &#39;数据删除成功,返回<a href="13-12.php">13-12.php</a>查看数据&#39;;
?>


本文地址:

转载随意,但请附上文章地址:-)

Stellungnahme
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn

Heiße KI -Werkzeuge

Undresser.AI Undress

Undresser.AI Undress

KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover

AI Clothes Remover

Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool

Undress AI Tool

Ausziehbilder kostenlos

Clothoff.io

Clothoff.io

KI-Kleiderentferner

AI Hentai Generator

AI Hentai Generator

Erstellen Sie kostenlos Ai Hentai.

Heißer Artikel

R.E.P.O. Energiekristalle erklärten und was sie tun (gelber Kristall)
3 Wochen vorBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Beste grafische Einstellungen
3 Wochen vorBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. So reparieren Sie Audio, wenn Sie niemanden hören können
3 Wochen vorBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: Wie man alles in Myrise freischaltet
3 Wochen vorBy尊渡假赌尊渡假赌尊渡假赌

Heiße Werkzeuge

SublimeText3 Mac-Version

SublimeText3 Mac-Version

Codebearbeitungssoftware auf Gottesniveau (SublimeText3)

SublimeText3 chinesische Version

SublimeText3 chinesische Version

Chinesische Version, sehr einfach zu bedienen

Senden Sie Studio 13.0.1

Senden Sie Studio 13.0.1

Leistungsstarke integrierte PHP-Entwicklungsumgebung

Notepad++7.3.1

Notepad++7.3.1

Einfach zu bedienender und kostenloser Code-Editor

SAP NetWeaver Server-Adapter für Eclipse

SAP NetWeaver Server-Adapter für Eclipse

Integrieren Sie Eclipse mit dem SAP NetWeaver-Anwendungsserver.