数据不从php session start变量存储到sql数据库

时间:2012-10-09 19:02:20

标签: php sql input

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

我在用户注册here.后查询用户的“电子邮件”,“名字”,“姓氏”和“约会”。但是,无论我做什么,用户输入都不会保存到数据库中。我认为但不确定这是我的session_start变量的问题。我认为会话没有正确启动/保存已注册的用户所特有的。我基于这个tutorial的代码,因为我是PHP的新手。

editprofile.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数据库中,我该如何解决这个问题。在此先感谢,如果需要更多代码,那么我愿意提供它。在注册网站时,可以访问表格here

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);
}
?>

1 个答案:

答案 0 :(得分:2)

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

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

所以这应该是:

$sql = "UPDATE `users` SET
        `user_email` = '{$email}',
        `user_about` = '{$about}'
    WHERE `user_id` = {$_SESSION['uid']}";