從你貼出來的代碼上來看,看不出所以然出來!

網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)建站!專注于網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、微信小程序定制開發(fā)、集團企業(yè)網(wǎng)站建設(shè)等服務(wù)項目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了潤州免費建站歡迎大家使用!
既然你錯了,你應該把相應的錯誤,或者提示,或者有疑問的地方反饋出來!
-----------
usr='".$user."',pwd='".$pwd."'
可能是你的這兩個條件中有些地方不滿足,而id=1可以修改正確,說明 sql語句本身是正確的!
在仔細看看看...
你要修改的這條數(shù)據(jù)的密碼在數(shù)據(jù)庫中是否加密?
不妨,先一個條件一個條件的去試試!
去掉where 條件就沒意義了!
$sql = mysql_query("UPDATE user_admin SET usr='".$user."' where id='".$id."'");
先去掉你的密碼條件
還有你上面的post的地方最好加上trim();
$sss = "UPDATE user_admin SET usr='".$user."' where id='".$id."'";
echo $sss; //這里可以分解,輸出來檢查!
$sql = mysql_query($sss);
方法是很多的,
取行的數(shù)據(jù)庫行的主鍵字段的值,然后對數(shù)據(jù)執(zhí)行更新操作:
update tabblename set xxx1 = 'aaaa',xxx2='bbbb' where id = 主鍵的值.
CI框架下的PHP增刪改查總結(jié):
controllers下的 cquery.php文件
[php] view plain copy
?php
class CQuery extends Controller {
//構(gòu)造函數(shù)
function CQuery() {
parent::Controller();
// $this-load-database();
}
function index() {
//調(diào)用model 其中train為外層文件夾 MQuery為model名稱 queryList為重命名
$this-load-model('train/MQuery','queryList');
//獲得返回的結(jié)果集 這里確定調(diào)用model中的哪個方法
$result = $this-queryList-queryList();
//將結(jié)果集賦給res
$this-smarty-assign('res',$result);
//跳轉(zhuǎn)到顯示頁面
$this-smarty-view('train/vquery.tpl');
}
//進入新增頁面
function addPage() {
$this-smarty-view('train/addPage.tpl');
}
//新增
function add() {
//獲得前臺數(shù)據(jù)
//用戶名
$memberName = $this-input-post('memberName');
//密碼
$password = $this-input-post('password');
//真實姓名
$userRealName = $this-input-post('userRealName');
//性別
$sex = $this-input-post('sex');
//出生日期
$bornDay = $this-input-post('bornDay');
//e_mail
$eMail = $this-input-post('eMail');
//密碼問題
$question = $this-input-post('question');
//密碼答案
$answer = $this-input-post('answer');
//調(diào)用model
$this-load-model('train/MQuery','addRecord');
//向model中的addRecord傳值
$result = $this-addRecord-addRecord($memberName,$password,$userRealName,$sex,$bornDay,$eMail,$question,$answer);
//判斷返回的結(jié)果,如果返回true,則調(diào)用本頁的index方法,不要寫 $result == false 因為返回的值未必是false 也有可能是""
if ($result) {
$this-index();
} else {
echo "add failed.";
}
}
//刪除
function deletePage() {
//獲得ID
$deleteID = $this-uri-segment(4);
//調(diào)用model
$this-load-model('train/MQuery','delRecord');
//將值傳入到model的delRecord方法中
$result = $this-delRecord-delRecord($deleteID);
//判斷返回值
if ($result) {
$this-index();
} else {
echo "delect failed.";
}
}
//修改先查詢
function changePage() {
$changeID = $this-uri-segment(4);
$this-load-model('train/MQuery','changeRecord');
$result = $this-changeRecord-changeRecord($changeID);
//將結(jié)果集賦給res
$this-smarty-assign('res',$result);
//跳轉(zhuǎn)到顯示頁面
$this-smarty-view('train/changePage.tpl');
}
//修改
function change() {
//獲得前臺數(shù)據(jù)
//ID
$ID = $this-input-post('id');
//用戶名
$memberName = $this-input-post('memberName');
//密碼
$password = $this-input-post('password');
//真實姓名
$userRealName = $this-input-post('userRealName');
//性別
$sex = $this-input-post('sex');
//出生日期
$bornDay = $this-input-post('bornDay');
//e_mail
$eMail = $this-input-post('eMail');
//密碼問題
$question = $this-input-post('question');
//密碼答案
$answer = $this-input-post('answer');
//調(diào)用model
$this-load-model('train/MQuery','change');
//向model中的change傳值
$result = $this-change-change($ID,$memberName,$password,$userRealName,$sex,$bornDay,$eMail,$question,$answer);
//判斷返回的結(jié)果,如果返回true,則調(diào)用本頁的index方法,不要寫 $result == false 因為返回的值未必是false 也有可能是""
if ($result) {
$this-index();
} else {
echo "change failed.";
}
}
}
models中的 mquery.php 文件
[php] view plain copy
?php
class MQuery extends Model {
//構(gòu)造函數(shù)
function MQuery() {
parent::Model();
//連接數(shù)據(jù)庫
$this-load-database();
}
//查詢列表
function queryList() {
//防止select出的數(shù)據(jù)存在亂碼問題
//mysql_query("SET NAMES GBK");
//SQL語句
$sql = "SELECT ID,member_name,sex,e_mail FROM user_info_t";
//執(zhí)行SQL
$rs = $this-db-query($sql);
//將查詢結(jié)果放入到結(jié)果集中
$result = $rs-result();
//關(guān)閉數(shù)據(jù)庫
$this-db-close();
//將結(jié)果集返回
return $result;
}
//新增
function addRecord($memberName,$password,$userRealName,$sex,$bornDay,$eMail,$question,$answer) {
//防止select出的數(shù)據(jù)存在亂碼問題
//mysql_query("SET NAMES GBK");
//SQL語句
$sql = "INSERT INTO user_info_t (member_name,password,user_real_name,sex,born_day,e_mail,question,answer) " .
"VALUES ('$memberName','$password','$userRealName','$sex','$bornDay','$eMail','$question','$answer')";
//執(zhí)行SQL
$result = $this-db-query($sql);
//關(guān)閉數(shù)據(jù)庫
$this-db-close();
//返回值
return $result;
}
//刪除
function delRecord($deleteID) {
//防止select出的數(shù)據(jù)存在亂碼問題
//mysql_query("SET NAMES GBK");
$sql = "DELETE FROM user_info_t WHERE ID = $deleteID";
$result = $this-db-query($sql);
$this-db-close();
return $result;
}
//修改前查詢
function changeRecord($changeID) {
//防止select出的數(shù)據(jù)存在亂碼問題
//mysql_query("SET NAMES GBK");
$sql = "SELECT ID,member_name,password,user_real_name,sex,born_day,e_mail,question,answer FROM user_info_t WHERE ID = $changeID";
//執(zhí)行SQL
$rs = $this-db-query($sql);
$result = $rs-row();//$result = $rs[0]
//關(guān)閉數(shù)據(jù)庫
$this-db-close();
//將結(jié)果集返回
return $result;
}
//修改
function change($ID,$memberName,$password,$userRealName,$sex,$bornDay,$eMail,$question,$answer) {
//防止select出的數(shù)據(jù)存在亂碼問題
//mysql_query("SET NAMES GBK");
//SQL語句
$sql = "update user_info_t set member_name = '$memberName',password = '$password', user_real_name = '$userRealName'," .
"sex = '$sex',born_day = '$bornDay',e_mail = '$eMail',question = '$question',answer = '$answer'" .
"where ID = $ID";
//執(zhí)行SQL
$result = $this-db-query($sql);
//關(guān)閉數(shù)據(jù)庫
$this-db-close();
//返回值
return $result;
}
}
views 下的 addPage.tpl文件
[php] view plain copy
html
head
/head
bodyform action="{{site_url url='train/cquery/add'}}" method="post"
table border='1'
tr
td用戶名/td
tdinput type="text" class="text" name="memberName" id="memberName"http://td
/tr
tr
td密碼/td
tdinput type="text" class="text" name="password" id="password"http://td
/tr
tr
td真實姓名/td
tdinput type="text" class="text" name="userRealName" id="userRealName"http://td
/tr
tr
td性別/td
tdinput type="text" class="text" name="sex" id="sex"http://td
/tr
tr
td出生日期/td
tdinput type="text" class="text" name="bornDay" id="bornDay"http://td
/tr
tr
tde_mail/td
tdinput type="text" class="text" name="eMail" id="eMail"http://td
/tr
tr
td密碼問題/td
tdinput type="text" class="text" name="question" id="question"http://td
/tr
tr
td密碼答案/td
tdinput type="text" class="text" name="answer" id="answer"http://td
/tr
/table
table
tr
tdinput type="submit" class="button" name="OK" value="提交" /
/td
/tr
/table/form
/body
/html
當前名稱:php數(shù)據(jù)修改 PHP數(shù)據(jù)修改
文章轉(zhuǎn)載:http://www.chinadenli.net/article26/dooiscg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供手機網(wǎng)站建設(shè)、網(wǎng)站設(shè)計公司、標簽優(yōu)化、外貿(mào)網(wǎng)站建設(shè)、面包屑導航、企業(yè)建站
聲明:本網(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)