如何在Mysql和php中更改单个用户的详细信息

如何在Mysql和php中更改单个用户的详细信息,php,mysql,Php,Mysql,嘿,我需要改变一个用户信息,但只有一个用户信息,所以举例来说 id username password Intro 1 Ryan **** 1 我只需要更改介绍部分? 我希望当用户浏览介绍,然后转到一个页面,其中用户介绍将更改为2,表示是的,他已经浏览了介绍 另外,如果它有助于我的数据库名为users,则发送一个SQL查询,如: update users set Intro=2 where id=1; 这个 您需要将yyy

嘿,我需要改变一个用户信息,但只有一个用户信息,所以举例来说

id    username     password      Intro
1       Ryan         ****          1
我只需要更改介绍部分? 我希望当用户浏览介绍,然后转到一个页面,其中用户介绍将更改为2,表示是的,他已经浏览了介绍


另外,如果它有助于我的数据库名为users,则发送一个SQL查询,如:

update users set Intro=2 where id=1;
这个

您需要将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...!';
}
?>

到目前为止您有什么?你有错误吗?
$id = (int) $id;
mysql_query("update users set intro = 2 where users.userid = $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...!';
}
?>