正如主题所述,我正在使用我的函数include文件来尝试设置“$ _SESSION ['username']”,以便我可以将它用作我网站部分的插入值,但我没有运气..
function change_profile_image($user_id, $file_temp, $file_extn) {
$file_path = 'images/profile/' . substr(md5(time()), 0, 10) . '.' . $file_extn;
move_uploaded_file($file_temp, $file_path);
mysql_query("UPDATE `users` SET `profile` = '" . mysql_real_escape_string($file_path) . "' WHERE `user_id` = " . (int)$user_id);
}
function mail_users($subject, $body) {
$query = mysql_query("SELECT `email`, `first_name` FROM `users` WHERE `allow_email` = 1");
while (($row = mysql_fetch_assoc($query)) !== false) {
email($row['email'], $subject, "Hello " . $row['first_name'] . ",\n\n" . $body);
}
}
function login($username, $password) {
$user_id = user_id_from_username($username);
$username = sanitize($username);
$username = $_SESSION['username'];
$password = md5($password);
return (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username' AND `password` = '$password'"), 0) == 1) ? $user_id : false;
}
所以我可以使用诸如
之类的字符串将它们插入到mysql中$category=$_POST['category'];
$sub_category=$_POST['sub_category'];
$topic_data=$_POST['topic_data'];
$posted=date("h:i:s d/m/Y"); //create date time
$sql="INSERT INTO `topics`(category, sub_category, topic_data, posted_by, posted)VALUES('$category', '$sub_category', '$topic_data', '" . $_SESSION['username'] . "', '$posted')";
$result=mysql_query($sql);
if($result){
header("Location: topics.php");
exit();
答案 0 :(得分:1)
你需要
$_SESSION['username'] = $username;
而不是
$username = $_SESSION['username'];
答案 1 :(得分:1)
你设置:
$username = $_SESSION['username'];
而不是:
$_SESSION['username'] = $username;