0

I keep getting this error when I try to explode the array by a comma, How to fix this error can anyone help me ???

friend_request.php

 <?php

     if(isset($_POST['acceptrequest'.$user_from]))
     {
         //select the friend array  row  from the logged in user
         $get_friend_check = mysql_query("SELECT friend_array FROM user WHERE user_name = '$login_user'") or die(mysql_error());
         $get_friend_row = mysql_fetch_assoc($get_friend_check);
         $friend_array = $get_friend_row['friend_array'];
         $friendArray_explode = explode(",", $friend_array);
         echo $friendArray_explode;
     }
     ?>

The last line of code produce this error how to fix it ??
Nemesis
  • 13
  • 2

2 Answers2

1

This is a NOTICE (not an error!) - you're trying to print an array as if it was a string. Use print_r or var_dump instead of echo:

print_r($friendArray_explode);
Nir Alfasi
  • 53,191
  • 11
  • 86
  • 129
0

this is because you are trying to pinrt an array as it was a string only using echo. For arrays you can use both print_r or var_dump

I would also sugeest you to stop using mysql_ api since they are depecrated, please switch to PDO or mysqli

Furthermore you are ready to mysql injection. there is a nice tutorial here which explain you everything about that -> How can I prevent SQL injection in PHP?

Community
  • 1
  • 1
Fabio
  • 23,183
  • 12
  • 55
  • 64