资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

php删除数据库指定成员,php数据库删除数据

PHP 删除SQL数据库表指定内容的简单问题。

比如你使用的数据库usrname/passwd为root/123456,database为test,新建了一个表为albums,有列artist,则最简单的代码实现如下:

专业领域包括成都网站设计、成都做网站、商城网站定制开发、微信营销、系统平台开发, 与其他网站设计及系统开发公司不同,创新互联的整合解决方案结合了帮做网络品牌建设经验和互联网整合营销的理念,并将策略和执行紧密结合,为客户提供全网互联网整合方案。

?php

if (isset($_POST["name"])) {

$conn = mysql_connect("localhost", "root", "123456") or die(mysql_error());

$select_db = mysql_select_db("test", $conn) or die(mysql_error());

$sql = 'select * from albums where artist = "' . $_POST["name"] . '"';

$rs = mysql_query($sql);

if ($rs) {

if (mysql_num_rows($rs) 0) {

$sql = 'delete from albums where artist = "' . $_POST["name"] . '"';

echo $sql;

echo "br";

$rs = mysql_query($sql);

if ($rs) {

echo $_POST["name"] . " delete successfully";

} else {

echo "delete fail: " . mysql_error();

}

} else {

echo "the name " . $_POST["name"] . " no exist in this database";

}

} else {

echo 'mysql fail: ' . mysql_error();

}

mysql_close($conn);

}

?

htmlhead

meta http-equiv="content-type" content="text/html;charset=utf-8"

/head

body

form enctype="multipart/form-data" action="test.php" method="POST"

label查询名字/label

input type="text" name="name" /

input type="submit" value="从数据中查询并删除"

/form

/body

/html

几种删除php数组中指定值元素的方法

array_splice函数可以删除数组中的元素(只是该函数的功能之一),array_splice用法如下:

array_splice — 把数组中的一部分去掉并用其它值取代

1

array array_splice( array $input, int $offset[, int $length = 0 [, mixed $replacement ]] )

把 input 数组中由offset 和 length指定的单元去掉,如果提供了 replacement 参数,则用其中的单元取代。

input:输入的数组。

offset:如果 offset 为正,则从 input数组中该值指定的偏移量开始移除。如果 offset为负,则从 input 末尾倒数该值指定的偏移量开始移除。

length:如果省略 length,则移除数组中从offset到结尾的所有部分。

如果指定了 length并且为正值,则移除这么多单元。

如果指定了 length并且为负值,则移除从 offset 到数组末尾倒数length 为止中间所有的单元。

小窍门:当给出了replacement 时要移除从 offset到数组末尾所有单元时,用count($input) 作为 length。

replacement:如果给出了 replacement 数组,则被移除的单元被此数组中的单元替代。

示例,删除数组$inputArr的第5~10个元素(从0开始数,包括第5个和第10个,共6个元素)

array_splice($inputArr,5,6);

如何用PHP语言删除已在数据库中存在的用户

$conn=new mysqli('localhost','root','pwd','database');//连接数据库

$conn-query("mysql命令");//执行数据库命令

$result=$conn-query("select * from table where name=' ' and password=' '");

$row=$result-fetch_array();//得到查询结果

if($row!=null){

$isok=$conn-query("delete * from table where name=' ' and password=' '");

}

echo $isok==1?"删除成功":"删除失败";//三元表达式,可以用if else代替


网页标题:php删除数据库指定成员,php数据库删除数据
URL标题:http://cdkjz.cn/article/hsdsip.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220