im fairly new to php im trying to create a login, ive been trying to figure out what is wrong for past 2 days and have tried everything but could not find a solution to this, ive asked people looked all over the net but could not find a proper solution.
I keep recieving this error when i try and login '
Notice: Array to string conversion in __________ on line 6 Welcome Array.
it seems like the array is causing the issue when i login i want it to display the users first name and last name. here is my code thanks in advance everyone :)
Login.php
<?php
require_once('connect.php');
include('includes/head.php');
?>
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post" >
<div class="container">
<fieldset>
<h2>Login</h2>
<div class="row">
<label class="fixedwidth">Username:</label>
<input type="text" name="username" required />
</div>
<div class="row">
<label class="fixedwidth">Password:</label>
<input type="password" name="password" />
</div>
<div class="row">
<input type="submit" name="submit" value="LogIn" />
</div>
</fieldset>
</div>
</form>
<?php
if(isset($_POST['submit'])) {
require_once('connect.php');
$username = mysqli_real_escape_string($connection, $_POST['username']);
$password = mysqli_real_escape_string($connection, $_POST['password']);
if(!empty($username) && !empty($password)) {
$query = "SELECT * FROM user where username='$username' and
password='$password'";
$result = mysqli_query($connection, $query);
$row=mysqli_fetch_array($result);
mysqli_close($connection);
if(mysqli_num_rows($result) ==1) {
$fullname=array(firstname=>$row['firstname'],lastname=>$row['lastname']);
session_start();
$_SESSION['user'] = $fullname;
header('Location: welcome.php');
}
else {
echo "<p>Could not find you in the database.</p>";
}
}
else {
echo "<p>Either the username or password are invalid. Please try
again</p>";
}
}
?>
Logout.php
<?php
session_start();
unset($_SESSION['user']);
// remove all session variables
session_destroy();
// destroy the session
header('Location: welcome.php');
?>
welcome.php
<?php
include('includes/head.php');
include('includes/nav2.php');
session_start();
echo 'Welcome '. $_SESSION['user'];
echo '<br><br>';
?>