php中添加、刪除、修改數(shù)據(jù)庫中的數(shù)據(jù)
網(wǎng)站建設(shè)哪家好,找成都創(chuàng)新互聯(lián)!專注于網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、小程序設(shè)計、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了通化免費(fèi)建站歡迎大家使用!
?php $id=mysql_connect(’localhost’,'root’,'root’);
mysql_select_db(’test1′,$id);
?
?php
if($_POST['denglu']==”提交”){
$name=$_POST[name];
$pass=$_POST[pass];
$query=”select * from aa where user=’$name’ and pass=’$pass’”;
$result=mysql_query($query);
if(mysql_num_rows($result)0)
{echo “$_POST[name].已經(jīng)通過”;}
else
{echo “$_POST[pass].沒有通過”;}}
?
?php echo “—————————-”;?
?php
if($_POST['tianjia']==”添加”){
$name=$_POST[name];
$pass=$_POST[pass];
$ip=$_POST[ip];
$querys=”select * from aa”;
$results=mysql_query($querys);
if($name==$user)
{echo “$_POST[name]已經(jīng)存在”;}
else
{
$query1=”insert into aa (user,pass,ip) values(’$name’,'$pass’,'$ip’)”;
$result1=mysql_query($query1);
echo “添加成功”;
}
}
?
?php echo “—————————-”;?
?php if($_POST['delete']==”刪除”){
$name=$_POST[name];
$pass=$_POST[pass];
$ip=$_POST[ip];
$query2=”delete from aa where user=’$name’”;
$result2=mysql_query($query2);
echo “刪除成功”;
}
?
?php echo “—————————-”;?
?php $query=”select * from aa”;
$result=mysql_query($query);
while($myrow=mysql_fetch_array($result)){?
style type=”text/css”
main{ width:890px; margin:0px; text-align:left; cursor: help}
.left{width:300px; margin-left:20px; font-size:12px; font-style:normal; text-align:left}
/style
div id=”main”
div class=”left”
table border=”0″p
tr
td?php echo $myrow[id];?,
?php echo $myrow[user];?,
?php echo $myrow[pass];?,
?php echo $myrow[ip];?/td
/tr
/table
?php }?
/div
為刪除按鈕增加一個sub句柄name=del,$_POST['sub']按鈕觸發(fā)sql處理刪除數(shù)據(jù)庫中的數(shù)據(jù),
我只能提供思想,實際問題實際對待。不懂的可以繼續(xù)問我。
這個需要分兩個步驟完成。
1、刪除數(shù)據(jù)庫數(shù)據(jù);
2、刪除文件。
一般存入數(shù)據(jù)庫的數(shù)據(jù)和文件都有關(guān)聯(lián)性,如文件名存在數(shù)據(jù)庫某字段中,這時候可以查詢出要刪除的某條數(shù)據(jù),找到這條數(shù)據(jù)中的文件名,然后先將這條數(shù)據(jù)刪除,再把文件名對應(yīng)的文件刪除。
刪除數(shù)據(jù)庫數(shù)據(jù)使用delete語法,刪除服務(wù)器文件使用unlink函數(shù)。
sample?code:
?php?
if($del_id!=""){?
$del_num=count($del_id);?
for($i=0;$i$del_num;$i++){?
mysql_query("Delete?from?news?where?id='$del_id[$i]'");?
}??
echo("script?type='text/javascript'alert('刪除成功!');history.back();/script");?
}else{?
echo("script?type='text/javascript'alert('請先選擇項目!');history.back();/script");?
}?
?
?php
delete($_POST[id]);
?
?php
delete("www");
?
把這東西放在delete函數(shù)下邊應(yīng)該就可以了
//刪除是記錄是用sql語句,比如 delete from xxx(table) where id=1 刪除 id=1的記錄
//數(shù)據(jù)庫操作后,手動關(guān)閉是好得習(xí)慣,不手動關(guān)閉,php程序也會最后自動關(guān)閉
網(wǎng)站標(biāo)題:php如何刪除數(shù)據(jù)表,php清空數(shù)據(jù)表
網(wǎng)頁網(wǎng)址:http://jinyejixie.com/article48/dsedsep.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供域名注冊、定制網(wǎng)站、小程序開發(fā)、ChatGPT、外貿(mào)建站、響應(yīng)式網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)