嘿,我需要更改用户信息,但只有一个用户信息,例如。如何更改Mysql和php中的单个用户详细信息
id username password Intro
1 Ryan **** 1
我需要更改只有介绍部分? 我希望这将改变,当用户通过介绍,然后去用户介绍将更改为2的页面,意味着他已经通过介绍..
以及如果它可以帮助我的数据库名字是用户
嘿,我需要更改用户信息,但只有一个用户信息,例如。如何更改Mysql和php中的单个用户详细信息
id username password Intro
1 Ryan **** 1
我需要更改只有介绍部分? 我希望这将改变,当用户通过介绍,然后去用户介绍将更改为2的页面,意味着他已经通过介绍..
以及如果它可以帮助我的数据库名字是用户
发送类似SQL查询:
update users set Intro=2 where id=1;
这?
UPDATE users SET intro = 1 WHERE id = 2
UPDATE users SET Intro = 2 WHERE id = 'yyy'
您需要YYY设置的登录用户
像这样的ID?
$id = (int) $id;
mysql_query("update users set intro = 2 where users.userid = $id;");
这可能是值得通过一些MySQL教程来给你一些基本知识。
假设你的用户表有主键ID,下面的代码会给你一个想法。
<?php
$server = ''; // server where your db is hosted
$username = ''; //username of the database
$password = ''; //password of the database
$dbname = ''; //database name of the server
$id = ''; //id of the user you want to change the intro flag of
$vlink = mysql_connect($server,$username,$password);
$dbselect = mysql_select_db($dbname);
//assuming the user already has a row in the table...
$query = 'SELECT COUNT(*) FROM user where id = "'. $id . '" and intro = 1';
$result = mysql_query($query,$vlink);
if(mysql_num_rows($result)>0)
echo 'User has already been through intro';
else
{
$query = 'UPDATE users SET intro = 2 WHERE id = ' . $id;
$result = mysql_query($query,$vlink);
if($result)
echo 'Success';
else
echo 'Failed...!';
}
?>
到目前为止你有什么?你有错误吗? – gmadd 2011-05-16 08:20:16