I’m trying to store user input in to my sql table as seen below,
my database http://goawaymom.com/test.png
I query the users for their ’email’, ‘firstname’, ‘last name’, and ‘about’ after they register here. However what ever I do, the user input does not save to the database. I THINK but am NOT sure that this is a problem with my session_start variable. I believe the session is not starting/saving properly unique to the user that has registered. I based my code of this tutorial as I am new to 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']);
}
?>
Any help would be greatly appreciated. Once again my question is, why isn’t the data from my editprofile.php form saving in to my php sql database and how do i fix this. Thanks in advance, and if more code is needed then I’d be willing to provide it. The form can be accessed here, upon registering for the website.
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);
}
?>
You cannot use ` around the strings {$email} and {$about}. Also right now you have {about} instead of {$about}. You are also using it for:
So this should be: