0

手头的问题:

如何创建 php 代码以让登录到我的站点的用户编辑/更新他们的个人资料设置/信息?

我有 1 部分可以正常工作,供用户更改密码,但是,在允许登录的用户编辑/更新他们的其他设置时,我不知道从哪里开始,例如:

(1)昵称, (2)国家, (3)出生日期, (4)性别, (5)座右铭和 (6)简历


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

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)中编辑/更新他们自己的配置文件设置/信息?

而且我知道使用 mysqli/pdo 是一个更好的选择,但不幸的是,我现在需要为这个项目使用旧的不推荐使用的 mysql_* 东西......

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

编辑:附加问题,

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

$nickname = $_POST['昵称'];

$country = $_POST['country'];

等等……还是不正确?

重新编辑

这样的事情是否适用?

$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"];
}

还是我离基地太远了?

4

1 回答 1

3

精简版 ;)

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>

更改.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
    }

?>
于 2013-08-20T21:17:25.070 回答