After successful login, I would like the function to keep the user_id, so the user can update their the profile in the database. In the database there are two rows called catchphrase and interest. Right now when I write something it creates a new column with user_id 0.
I get this error as well: Notice: Array to string conversion in
/Applications/XAMPP/xamppfiles/htdocs/modul8B/models/profile_table_class.php on line 23
Line 23 is:
$data = array ($catchphrase, $interest, $image);
Here's the code for inserting:
class Profile_Table {
private $db;
public function __construct($pdo) {
$this->db = $pdo;
;
}
public function getProfileForUser($user_id){
$sql = "SELECT user_id, catchphrase, interest, image FROM user
WHERE user_id = ?";
$statement = $this->db->prepare($sql);
$data = array( $user_id);
$statement->execute($data);
//print_r($statement);
return $statement->fetchObject();
}
public function insertProfile($catchphrase, $interest, $image){
$sql = "INSERT INTO user (catchphrase, interest, image) values ('".$catchphrase."', '".$interest."', '".$image."')";
$statement = $this->db->prepare($sql);
$data = array ($catchphrase, $interest, $image);
$statement->execute ($data);
return $statement;
}
and here's the home page:
<?php
if ($siteVisitor->IsLoggedIn()) {
//echo "catchphrase = $catchphrase<br>";
include_once "models/profile_table_class.php";
$profiles = new Profile_Table($db);
$userId = $siteVisitor->getId();
$profileData = $profiles->getProfileForUser($userId);
//die();
$homeOutput = include_once 'views/loggedIn.php';
$homeOutput .= include_once "views/profile-list-html.php";
$profileIsSubmitted = isset($_POST['profile-submit']);
if ($profileIsSubmitted) {
$catchphrase = $_POST['catchphrase'];
$interest = $_POST['interest'];
$image = $_FILES['image'];
try {
$profiles->insertProfile($catchphrase, $interest, $image);
} catch (Exception $e) {
$errorDescription = $e;
echo $e;
}
}
return $homeOutput;
Any help appreciated.