1

我正在尝试将用户输入存储到我的 sql 表中,如下所示, 我的数据库 http://goawaymom.com/test.png

在这里注册后,我向用户查询他们的“电子邮件”、“名字”、“姓氏”和“关于” 但是无论我做什么,用户输入都不会保存到数据库中。我认为但不确定这是我的 session_start 变量的问题。我相信会话没有正确启动/保存对于已注册的用户来说是唯一的。我基于本教程的代码,因为我是 PHP 新手。

编辑配置文件.php

<?php
session_start();

include('core/init_inc.php');

if(isset($_POST['email'], $_POST['about'], $_POST['firstname'], $_POST['lastname'])){
$errors = array();   
if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false){
    $errors[] = 'The email address you entered is not valid';    
}
if (empty($errors)){
    set_profile_info($_POST['email'],$_POST['about']);
}
$user_info = array(
    'email'     => htmlentities($_POST['email']),
    'about'     => htmlentities($_POST['about']),
    'firstname'     => htmlentities($_POST['firstname']),
    'lastname'     => htmlentities($_POST['lastname'])
);
} else {
$user_info = fetch_user_info($SESSION['uid']);
}
?>

任何帮助将不胜感激。我的问题再次是,为什么我的 editprofile.php 表单中的数据没有保存到我的 php sql 数据库中,我该如何解决这个问题。提前致谢,如果需要更多代码,我愿意提供。注册网站后,可在此处访问该表格。

function fetch_users() {
$result = mysql_query('SELECT `user_id` AS `id`, `username` FROM `users`');

$users = array ();

while (($row = mysql_fetch_assoc($result)) !== false){
    $users[ ] = $row;
}


return $users;

}
//fetches profile information for the given user
function fetch_user_info($uid){
$uid = (int)$uid;

$sql = "SELECT
            `username`,
            `user_firstname` AS `firstname`,
            `user_lastname` AS `lastname`,
            `user_about` AS `about`,
            `user_email` AS `email`
        FROM `users`
        WHERE `user_id` = {$uid}";

$result = mysql_query($sql);        
return mysql_fetch_assoc($result);


}

//updates the current user profile info
function set_profile_info($email, $about){
$email = mysql_real_escape_string(htmlentities($email));
$about = mysql_real_escape_string(nl2br(htmlentities($about)));


$sql = "UPDATE `users` SET
        `user_email` = `{$email}`,
        `user_about` = `{about}`
    WHERE `user_id` = {$_SESSION[`uid`]}";
mysql_query($sql);
}
?>
4

1 回答 1

2

您不能在字符串 {$email} 和 {$about} 周围使用 `。现在你还有 {about} 而不是 {$about}。您还将它用于:

$_SESSION[`uid`] //needs to be $_SESSION['uid']

所以这应该是:

$sql = "UPDATE `users` SET
        `user_email` = '{$email}',
        `user_about` = '{$about}'
    WHERE `user_id` = {$_SESSION['uid']}";
于 2012-10-09T19:12:34.863 回答