1

以下に示すように、ユーザー入力をSQLテーブルに保存しようとして います。データベース http://goawaymom.com/test.png

ユーザーがここに登録した後、ユーザーに「email」、「firstname」、「last name」、および「about」を照会します ただし、何をしても、ユーザー入力はデータベースに保存されません。と思いますが、これが私の session_start 変数に問題があるかどうかはわかりません。登録したユーザーに固有のセッションが適切に開始/保存されていないと思います。私は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 データベースに保存されないのはなぜですか、どうすればこれを修正できますか。事前に感謝します。さらにコードが必要な場合は、喜んで提供します。フォームは、ウェブサイトに登録すると、ここからアクセスできます。

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 に答える