新聞中心
php數(shù)據(jù)庫內(nèi)容修改代碼
修改如下:不用使用session傳遞
我們提供的服務有:成都網(wǎng)站建設、成都做網(wǎng)站、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認證、城步ssl等。為上1000家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務,是有科學管理、有技術的城步網(wǎng)站制作公司
1.php 文件中: 修改后的代碼,將$row["id"]作為id的參數(shù)值傳遞到2.php
else{
echo 'td'.'a href="2.php?id='.$row["id"].'"'.$row["id"].可以修改.'/a/td';
}
2.php修改如下:
$strSql="SELECT * from test where id=".$_GET['id'];
php 點擊按鈕 直接更改數(shù)據(jù)庫 類似審核功能
具體情況具體分析
流程大概是這樣的:
button的onclick事件觸發(fā)-ajax請求后臺-后臺修改返回數(shù)據(jù)-前臺接受到數(shù)據(jù)js修改button 的value
PHP怎樣修改數(shù)據(jù)庫信息
?php
mysql_connect('127.0.0.1','root','123456');
$sql="update?sjk._sjk?set?b='1',c='1'?where?a='123'";
if?(mysql_query($sql))?echo?'修改成功。';
else?echo?"修改失敗,SQL:$sqlbr錯誤:".mysql_error();
mysql_close();
?
如何用php修改數(shù)據(jù)庫中的數(shù)據(jù)
舉例如下:
創(chuàng)建userinfo_update.php頁面用于查詢用戶信息,先顯示信息,在修改:
先通過GET獲取用戶編號查詢用戶信息:
$sql = "select * from user_info where user_id='".$_GET['userId']."'";
$result = mysql_query($sql,$con);
if($row = mysql_fetch_array($result)){
}
頁面效果:
創(chuàng)建update.php文件,用于修改用戶信息:
使用到了mysql_affected_rows() 函數(shù)返回前一次 MySQL 操作所影響的記錄行數(shù)。
//通過post獲取頁面提交數(shù)據(jù)信息
$userId = $_POST[userId];
$userName = $_POST[userName];
$userAge = $_POST[userAge];
$sql = "update user_info set user_name='".$userName."',user_age=".$userAge." where user_id='".$userId."'";
mysql_query($sql,$conn);//執(zhí)行SQL
$mark? = mysql_affected_rows();//返回影響行數(shù)
$url = "userinf_select.php";
運行結果
創(chuàng)建delete.php文件,完成刪除用戶信息功能:
$userId = $_GET['userId'];
include 'connection.php';
$sql = "delete from user_info where user_id='".$userId."'";
mysql_query($sql,$con);
$mark? = mysql_affected_rows();//返回影響行數(shù)
if($mark0){
echo "刪除成功";
}else{
echo? "刪除失敗";
}
mysql_close($con);
運行結果:
文章名稱:php鍵修改數(shù)據(jù)庫,怎么修改php
鏈接地址:http://www.dlmjj.cn/article/dsigeod.html