如何允许用户登录到UPDATE/EDIT他们的配置文件设置/信息 [英] how to allow users logged in to UPDATE / EDIT their profile settings/information

查看:76
本文介绍了如何允许用户登录到UPDATE/EDIT他们的配置文件设置/信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

眼前的问题:

如何创建php代码,以允许登录到我的网站的用户编辑/更新其个人资料设置/信息?

我有1个部分可以正常工作,以便用户更改密码,但是,对于允许登录用户编辑/更新其他设置(例如:

I have 1 part working correctly for users to change their password, however, have no idea where to start when it comes to allowing users who are logged in to edit/update their other settings such as:

(1)昵称, (2)国家/地区, (3)的生日, (4)性别, (5)座右铭和 (6)个人简介

(1) nickname, (2) country, (3) date of birth, (4) gender, (5) motto and (6) bio

我将在下面提供用于更改密码的php和html代码,但我知道我需要更多让用户更改/编辑/更新其其他信息的代码.我尝试使用下面的内容作为参考来创建其他信息的php代码,但是它没有用,所以我什至不知道从哪里开始!任何帮助将不胜感激...

I'll provide the php and html code below that I have that is working for changing password, but I know that I need more to let users change/edit/update their other information. I tried using what is below as a reference to create the php code for the other information, but it didn't work so I have no idea where to even begin! Any help will be much appreciated...

PHP参考代码:

if($_POST['submit']=='Change')
{
    $err = array();
    if(!$_POST['password1'] || !$_POST['passwordnew1'])
        $err[] = 'All the fields must be filled in!';
    if(!count($err))
    {
        $_POST['password1'] = mysql_real_escape_string($_POST['password1']);
        $_POST['passwordnew1'] = mysql_real_escape_string($_POST['passwordnew1']);
        $row = mysql_fetch_assoc(mysql_query("SELECT id,username FROM members WHERE username='{$_SESSION['username']}' AND pass='".md5($_POST['password1'])."'"));
        if($row['username'])
    {
        $querynewpass = "UPDATE members SET pass='".md5($_POST['passwordnew1'])."' WHERE username='{$_SESSION['username']}'";
        $result = mysql_query($querynewpass) or die(mysql_error());
        $_SESSION['msg']['passwordchange-success']='* You have successfully changed your password!';
    }
        else $err[]='Wrong password to start with!';
    }
    if($err)
    $_SESSION['msg']['passwordchange-err'] = implode('<br />',$err);
    header("Location: members.php?id=" . $_SESSION['username']);
    exit;
}

HTML参考代码:

<form action="" method="post"> 
    <label class="grey" for="password1">Current Password:</label>
    <input class="field" type="password" name="password1" id="password1" value="" size="23" />
    <label class="grey" for="password">New Password:</label>
    <input class="field" type="password" name="passwordnew1" id="passwordnew1" size="23" />
    <input type="submit" name="submit" value="Change" class="bt_register" style="margin-left: 382px;" />
      <div class="clear"></div>
    <?php
    if($_SESSION['msg']['passwordchange-err'])
    {
        echo '<div class="err">'.$_SESSION['msg']['passwordchange-err'].'</div>';
        unset($_SESSION['msg']['passwordchange-err']);
    }
    if($_SESSION['msg']['passwordchange-success'])
    {
        echo '<div class="success">'.$_SESSION['msg']['passwordchange-success'].'</div>';
        unset($_SESSION['msg']['passwordchange-success']);
    }
    ?>
</form>

那么我将如何创建php代码以使用户能够通过我上面提供的数字列表(1-6)来编辑/更新自己的个人资料设置/信息呢?

So how would I create the php code to make this work for users to be able to edit/update their own profile settings/information from the numeric list I provided above (1-6)?

我知道使用mysqli/pdo是更好的选择,但是很不幸,目前我需要为此项目使用旧的mysql_ *旧版本...

And I know using mysqli/pdo is a better alternative to use, but I unfortunately need to use the old deprecated mysql_* stuff for this project at this time...

如果您需要更多信息,请告诉我;)

If you need more info, let me know ;)

编辑: 附加问题,

我也假设我也需要为每列创建变量,例如:

I'd assume too that I'd need to create variables for each column too such as:

$ nickname = $ _POST ['nickname'];

$nickname = $_POST['nickname'];

$ country = $ _POST ['country'];

$country = $_POST['country'];

等等...还是不正确?

etc...or is that not correct?

重新编辑:

这样适用吗?

$id = $_SESSION['id'];
if ($_POST['country']) {
    $country = $_POST['country'];
    $nickname = $_POST['nickname'];
    $DOB = $_POST['DOB'];
    $gender = $_POST['gender'];
    $motto = $_POST['motto'];
    $bio = $_POST['bio'];
    $sql = mysql_query("UPDATE members SET country='$country', nickname='$nickname', DOB='$DOB', gender='$gender', motto='$motto', bio='$bio' WHERE id='$id'"); 

exit;
}

$sql = mysql_query("SELECT * FROM members WHERE id='$id' LIMIT 1");
while($row = mysql_fetch_array($sql)){
$country = $row["country"];
$nickname = $row["nickname"];
$DOB = $row["DOB"];
$gender = $row["gender"];
$motto = $row["motto"];
$bio = $row["bio"];
}

还是我偏离了基地?

推荐答案

短版本;)

HTML文件:

<form action="./change.php" method="post"> 
    Nickname: <input type="text" name="nickname"><br />
    Country: <input type="text" name="country"><br />
    Date of birth: <input type="text" name="date_of_birth"><br />
    Gender: <input type="text" name="gender"><br />
    Motto: <input type="text" name="motto"><br />
    Bio: <input type="text" name="bio"><br />
    <input type="submit" value="Submit">
</form>

change.php:

change.php:

<?php
    function filter($date)
    {
        return trim(htmlspecialchars($date));
    }

    $nickname = filter($_POST['nickname'])
    $country = filter($_POST['country'])
    $date_of_birth = filter($_POST['date_of_birth'])
    $gender = filter($_POST['gender'])
    $motto = filter($_POST['motto'])
    $bio = filter($_POST['bio'])

    if (isUserLogIn)
    {
        //SQL update query
    }

?>

这篇关于如何允许用户登录到UPDATE/EDIT他们的配置文件设置/信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆