By using the following function I get that error, the function is used to verify whether or not there is a string in DB
, if it does not remove that error, but if it does not exist I get the error
"Notice: Undefined offset: 0"
I have already verified the code, the connection to the DB and everything is correct. This function I had previously used on another page, and it worked properly for me, but now that I have moved on to another project, it does not work for me and I made sure everything was well written.
<?php
function selectUser($username){
try{
$con = connect();
$query = "SELECT * FROM accounts WHERE user = :user";
$stmt = $con->prepare($query);
$stmt->execute(array(
':user' => $username
));
$result = $stmt->fetchAll();
return $result;
$con = null;
}catch (PDOException $e) {
return 'Connection Failed: ' . $e->getMessage();
}
}
?>