php数据修改方法 php修改数据表内容( 二 )


//连接数据库
$this-load-database();
}
//查询列表
function queryList() {
//防止select出的数据存在乱码问题
//mysql_query("SET NAMES GBK");
//SQL语句
$sql = "SELECT ID,member_name,sex,e_mail FROM user_info_t";
//执行SQL
$rs = $this-db-query($sql);
//将查询结果放入到结果集中
$result = $rs-result();
//关闭数据库
$this-db-close();
//将结果集返回
return $result;
}
//新增
function addRecord($memberName,$password,$userRealName,$sex,$bornDay,$eMail,$question,$answer) {
//防止select出的数据存在乱码问题
//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')";
//执行SQL
$result = $this-db-query($sql);
//关闭数据库
$this-db-close();
//返回值
return $result;
}
//删除
function delRecord($deleteID) {
//防止select出的数据存在乱码问题
//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出的数据存在乱码问题
//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";
//执行SQL
$rs = $this-db-query($sql);
$result = $rs-row();//$result = $rs[0]
//关闭数据库
$this-db-close();
//将结果集返回
return $result;
}
//修改
function change($ID,$memberName,$password,$userRealName,$sex,$bornDay,$eMail,$question,$answer) {
//防止select出的数据存在乱码问题
//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";
//执行SQL
$result = $this-db-query($sql);
//关闭数据库
$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"//td
/tr
tr
td密码/td
tdinput type="text" class="text" name="password" id="password"//td
/tr
tr
td真实姓名/td
tdinput type="text" class="text" name="userRealName" id="userRealName"//td
/tr
tr
td性别/td
tdinput type="text" class="text" name="sex" id="sex"//td
/tr
tr
td出生日期/td
tdinput type="text" class="text" name="bornDay" id="bornDay"//td
/tr
tr
tde_mail/td
tdinput type="text" class="text" name="eMail" id="eMail"//td
/tr
tr
td密码问题/td
tdinput type="text" class="text" name="question" id="question"//td
/tr
tr
td密码答案/td
tdinput type="text" class="text" name="answer" id="answer"//td
/tr
/table
table
tr
tdinput type="submit" class="button" name="OK" value="https://www.04ip.com/post/提交" /
/td
/tr
/table/form
/body
/html
php数据库添加、删除、修改数据(mysql)一、PHP操作MySql数据库
新增数据
?php
$query
=
"INSERT

推荐阅读