-3

I am trying to insert an array into table (below):

$arr = implode(',',$_POST['name']); 
$sql = "INSERT INTO test (name) VALUES ($arr)";
$mysqli->query($sql);

but im getting this error:

Fatal error: Call to a member function query() on a non-object

Any idea what is going on?

Kelson Batista
  • 406
  • 4
  • 25
  • Quote your values, check your connection and what's passing through. – Funk Forty Niner Feb 18 '15 at 03:07
  • not duplicate my friend... that post is about connection and mine is ok – Kelson Batista Feb 18 '15 at 03:17
  • Well non-object can mean a lot of things. Bad connection, not using the same API, wrong DB chosen, wrong table, wrong column, wrong POST; who knows. Add error reporting to the top of your file(s) right after your opening PHP tag for example ` – Funk Forty Niner Feb 18 '15 at 03:20
  • please echo the $sql show the result to us – Varun Naharia Feb 18 '15 at 03:26
  • *"not duplicate my friend... that post is about connection and mine is ok"* - You're using `$mysqli` in the question but your answer contains `$conn`. – Funk Forty Niner Feb 18 '15 at 03:43
  • The error message is pretty clear: you're trying to call a method on something that isn't an object. Figure out what `$mysqli` is and change your code to make sure that it's an object that has a `query` method (or change your code to not call that method). –  Feb 18 '15 at 04:11

1 Answers1

0

The problem was the mysqli_query

$arr = implode(',',$_POST['name']); 
$sql = "INSERT INTO teste (item) VALUES ('$arr')";
mysqli_query($conn,$sql);
Kelson Batista
  • 406
  • 4
  • 25