0

Normally, this kind of error shows up when trying to perform a mysql_fetch_array to a query that's faulty, however I am constantly getting this error despite the query is being performed (it's an insert, I can check the new entrances in phpmyadmin).

For example, the output for this:

$query= mysql_query("INSERT INTO `objects` (`idObjects`, `obj_type`, `obj_name`, `obj_cdate`, `availability`, `status`, `User_idUser`) VALUES (NULL, '$type', 'EL TESTE', '$final', 'Public', 'Active', '13')");
$insert_place = mysql_fetch_array($query, MYSQL_ASSOC);
if (!$insert_place) {
   die('Invalid query: ' . mysql_error());

is Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\neo4play\factualimport.php on line 22 Invalid query:

with no error provided, and that row is still inserted into the database. Any clue what might be causing this?

2
  • 1
    Inserts don't return arrays, and you should not use mysql_ functions in new development either. Commented Jun 27, 2014 at 20:45
  • 2
    Stop using mysql, it's deprecated and not secure. Use mysqli or PDO. Commented Jun 27, 2014 at 20:45

1 Answer 1

1

You can't fetch an INSERT query as it is not returning rows. You use mysql_fetch_array() with a SELECT statement to return an array of data from the query. Take out:

$insert_place = mysql_fetch_array($query, MYSQL_ASSOC);

and replace:

if (!$insert_place) 

with:

if (!$query) 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.