Hello i im confuzed with this problem, i have converted the php code into the right format MySQLi
and i get this wierd error Notice: Array to string conversion in C:\xampp\htdocs\Training\core.php on line 25
So i dont know where is the problem in the login.php
or core.php
look at the codes and please tell me where should i correct something thank you :)
function getUserData($field) {
$DBServer = 'localhost';
$DBUser = 'root';
$DBPass = '';
$DBName = 'upstrey';
$conn = new mysqli($DBServer, $DBUser, $DBPass, $DBName);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT `$field` FROM `users` WHERE `ID`='".$_SESSION['user_id']."'"; // this is the line 25 in the error
$result = $conn->query($sql);
if ($result->num_rows > 0) {
if($row = fetch_assoc($result)) {
return $row["$field"];
}
// so i want to make getUserData function so i can use it like getUserData('First Name') in other files
}
$conn->close();
}
login.php
if($result->num_rows > 0) {
session_start();
$user_id = mysqli_fetch_row($result);
$_SESSION['user_id'] = $user_id;
/*$_SESSION['user_id'] = "1"; <-- this line giving me data from the first ID in the database*/
header('Location: home.php');
echo "Email and Password Accepted";
} else {
session_start();
$_SESSION['user_id'] = ''; // and also tell me if this line is ok ?
echo "Invalid Email or Password";
}
Thank you again