求一段PHP代码,请高手们帮帮忙........................谢谢!!!
是关于后台修改密码和帐号的。$_SESSION['user'];原账号:text1=o_account原密码:text2=o_pwd新帐号:text3=n_account...
是关于后台修改密码和帐号的。
$_SESSION['user'];
原账号:text1=o_account 原密码: text2=o_pwd
新帐号:text3=n_account 新密码:text4=n_pwd
数据库表名:forever_admin
字段:id, name,password
name是唯一的。 展开
$_SESSION['user'];
原账号:text1=o_account 原密码: text2=o_pwd
新帐号:text3=n_account 新密码:text4=n_pwd
数据库表名:forever_admin
字段:id, name,password
name是唯一的。 展开
2个回答
展开全部
<?php
//create conect
$con = mysql_connect("localhost:3306","root","angel");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
//create database
//echo mysql_query("CREATE DATABASE php_test_db",$con) . "<br";
//select database
mysql_select_db("php_test_db", $con) ;
//create table
$sql = "CREATE TABLE forever_admin
(
name varchar(15),
password varchar(15)
)";
//echo mysql_query(,$con) ."<br";
//query data
$sql = "select * from forever_admin where name='" . $_REQUEST[o_account] . "'";
echo $sql . "<br>";
$result = mysql_query($sql);
if(mysql_num_rows($result))
{
$sql = "select * from forever_admin where name='" . $_REQUEST[o_account] . "' and password='" . $_REQUEST[o_pwd] . "'";
echo $sql . "<br>";
$result = mysql_query($sql);
if(mysql_num_rows($result))
{
$sql = "update forever_admin set name='" . $_REQUEST[n_account] . "', password='" . $_REQUEST[n_pwd] . "' where name='" . $_REQUEST[o_account] . "'";
echo $sql . "<br>";
$result = mysql_query($sql);
if( mysql_affected_rows())
{
echo "update <span style='color:red;'>success</span><br>";
}
else
{
echo "update <span style='color:red;'>failed</span><br>";
}
}
else
{
echo "wrong password<br>";
}
}
else
{
echo "the account:<span style='color:red;'>" . $_REQUEST[o_account] . "</span> not exits<br>";
}
//close connect
mysql_close($con);
?>
<head>
<title>修改密码</title>
<style>
.table-head
{
background:#6796B4;
color:#E5FEFF;
font:"宋体";
font-size:15px;
width:100%;
height:32;
overflow:hidden;
}
TD, TH
{
font:"宋体";
font-size:12px;
height:32;
vertical-align:middle;
border:thin;
border-bottom:1px solid #464646;
border-left:1px solid #464646;
border-right:1px solid #464646;
}
</style>
<script>
String.prototype.trim=function() { return this.replace(/(^\s*)|(\s*$)/g,""); }
function checkform()
{
if(document.getElementById("o_account").value.trim()=="")
{
alert("原账号不能为空");
return false;
}
if(document.getElementById("o_pwd").value.trim()=="")
{
alert("原密码不能为空");
return false;
}
if(document.getElementById("n_account").value.trim()=="")
{
alert("新账号不能为空");
return false;
}
if(document.getElementById("n_pwd").value.trim()=="")
{
alert("新密码不能为空");
return false;
}
return true;
}
function getTarget()
{
return "modify_password.php";
}
</script>
</head>
<body>
<form method="get" target="getTarget()" onsubmit="return checkform()">
<table width="667" border="0" align="center" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2" align="center" style="background:#6796B4;color:#E5FEFF;font:宋体;font-size:15px;height:32;overflow:hidden;">修改密码</td>
</tr>
<tr>
<td width="100"> 原账号:</td>
<td > <input type="text" name="o_account"/></td>
</tr>
<tr>
<td> 原密码:</td>
<td> <input type="password" name="o_pwd"/></td>
</tr>
<tr>
<td> 新账号:</td>
<td> <input type="text" name="n_account" /></td>
</tr>
<tr>
<td> 新密码:</td>
<td> <input type="password" name="n_pwd" /></td>
</tr>
<tr>
<td> </td>
<td> <input type="submit" value="提交" /></td>
</tr>
</table>
</form>
</body>
</html>
刚学php哈,共同进步吧! ^_^
那 id 和 name 的作用是一样的。上面的代码出来创建数据库表 forever_admin
的 SQL 语句不同外,其他都一样的。
//create conect
$con = mysql_connect("localhost:3306","root","angel");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
//create database
//echo mysql_query("CREATE DATABASE php_test_db",$con) . "<br";
//select database
mysql_select_db("php_test_db", $con) ;
//create table
$sql = "CREATE TABLE forever_admin
(
name varchar(15),
password varchar(15)
)";
//echo mysql_query(,$con) ."<br";
//query data
$sql = "select * from forever_admin where name='" . $_REQUEST[o_account] . "'";
echo $sql . "<br>";
$result = mysql_query($sql);
if(mysql_num_rows($result))
{
$sql = "select * from forever_admin where name='" . $_REQUEST[o_account] . "' and password='" . $_REQUEST[o_pwd] . "'";
echo $sql . "<br>";
$result = mysql_query($sql);
if(mysql_num_rows($result))
{
$sql = "update forever_admin set name='" . $_REQUEST[n_account] . "', password='" . $_REQUEST[n_pwd] . "' where name='" . $_REQUEST[o_account] . "'";
echo $sql . "<br>";
$result = mysql_query($sql);
if( mysql_affected_rows())
{
echo "update <span style='color:red;'>success</span><br>";
}
else
{
echo "update <span style='color:red;'>failed</span><br>";
}
}
else
{
echo "wrong password<br>";
}
}
else
{
echo "the account:<span style='color:red;'>" . $_REQUEST[o_account] . "</span> not exits<br>";
}
//close connect
mysql_close($con);
?>
<head>
<title>修改密码</title>
<style>
.table-head
{
background:#6796B4;
color:#E5FEFF;
font:"宋体";
font-size:15px;
width:100%;
height:32;
overflow:hidden;
}
TD, TH
{
font:"宋体";
font-size:12px;
height:32;
vertical-align:middle;
border:thin;
border-bottom:1px solid #464646;
border-left:1px solid #464646;
border-right:1px solid #464646;
}
</style>
<script>
String.prototype.trim=function() { return this.replace(/(^\s*)|(\s*$)/g,""); }
function checkform()
{
if(document.getElementById("o_account").value.trim()=="")
{
alert("原账号不能为空");
return false;
}
if(document.getElementById("o_pwd").value.trim()=="")
{
alert("原密码不能为空");
return false;
}
if(document.getElementById("n_account").value.trim()=="")
{
alert("新账号不能为空");
return false;
}
if(document.getElementById("n_pwd").value.trim()=="")
{
alert("新密码不能为空");
return false;
}
return true;
}
function getTarget()
{
return "modify_password.php";
}
</script>
</head>
<body>
<form method="get" target="getTarget()" onsubmit="return checkform()">
<table width="667" border="0" align="center" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2" align="center" style="background:#6796B4;color:#E5FEFF;font:宋体;font-size:15px;height:32;overflow:hidden;">修改密码</td>
</tr>
<tr>
<td width="100"> 原账号:</td>
<td > <input type="text" name="o_account"/></td>
</tr>
<tr>
<td> 原密码:</td>
<td> <input type="password" name="o_pwd"/></td>
</tr>
<tr>
<td> 新账号:</td>
<td> <input type="text" name="n_account" /></td>
</tr>
<tr>
<td> 新密码:</td>
<td> <input type="password" name="n_pwd" /></td>
</tr>
<tr>
<td> </td>
<td> <input type="submit" value="提交" /></td>
</tr>
</table>
</form>
</body>
</html>
刚学php哈,共同进步吧! ^_^
那 id 和 name 的作用是一样的。上面的代码出来创建数据库表 forever_admin
的 SQL 语句不同外,其他都一样的。
2011-02-15
展开全部
数据表 就这两个字段 怎么可能连帐号一起改啊,还有别的字段吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询