0

im trying to return an array of messages but i get this error :

Notice: Array to string conversion in ($sql="select UTLR_UID from adm_utilisateurs where UTLR_LOGIN='$user' and UTLR_MDP='$mdp'";)

Here is my code :

 function getHistoriqueNotification($user,$mdp){
    $com = new DbConnect();
    $sql="select UTLR_UID from adm_utilisateurs where UTLR_LOGIN='$user' and UTLR_MDP='$mdp'";
    $result=mysqli_query($com->getDb(),$sql);
    $getID = mysqli_fetch_assoc($result);
    $userID = $getID['UTLR_UID'];
    $sqli = "SELECT AHIS_DES_LN1
    FROM alr_historiques
    WHERE UTLR_UID=$userID";
    $resulti = mysqli_query($com->getDb(),$sqli);
    while($row=mysqli_fetch_assoc($resulti)){
    $AHIS_DES_LN1=$row['AHIS_DES_LN1'];
    $msg = array(
    'message' => '$AHIS_DES_LN1'
    );
    } 
    return $msg;
    } 
k.groom
  • 11
  • 3
  • `$user` or `$mdp` is likely an array. – Scuzzy Apr 15 '18 at 21:38
  • 1
    Other notes.... `'$AHIS_DES_LN1'` will be literal. To be the variable's value remove the quotes. Don't use quotes when they aren't needed, this will save you time in the future. Your `$user` and/or `$mdp` is possibly opening you to SQL injections. Your query should be parameterized. – chris85 Apr 15 '18 at 21:43

1 Answers1

0

It seems either $user or $mdp is of the type array. You cannot use this in SQL. You need to convert your array into a string.

Try to var_dump($user) and var_dump($mdpd) to see which one is an array. After that convert it into a string. The error should be gone.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
sietse85
  • 1,488
  • 1
  • 10
  • 26