The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End mysqli_fetch_assoc() expects parameter 1 to be mysqli_result error Re: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result error


> Most of what you are saying is over my head. I am in a beginner PHP course.

Not a problem. Have you discussed this code in class yet? I would hope your instructor helps you understand what code *does* before expecting you to use it.

> I do not know how to test the code besides running it in the browser and seeing what errors I get.

Actually, that’s a great method.

> If there are any tools you know about to test the code that would be helpful.

A good text editor can be a great help, by highlighting your code, pointing out syntax errors, and so forth – I use [Komodo]( (Komodo Edit is free and runs on Linux/Windows/Mac), but there are many good choices out there.

> This is the error I get: `Invalid query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘where id = ”’ at line 1`

**Very** helpful.

That means something is going wrong when you try to write your query – near the part that says “where id=”. Print it out and see what it actually says:

// after this line:
$sql = “SELECT * FROM $table where id = ‘$id'”;
// do this:
exit( $sql );

That should print the SQL query you’re generating to the screen, so you can see what MySQL sees.

*(My guess is that your variable `$id` holds something that creates a syntax error.)*

> I do not know what a control structure is. I don’t know what mean by checking if the query is successful before trying to use the results.

A *control structure* helps decide *how your program runs*. In this case, I’m talking about using an `if{}` structure to make sure you only try to fetch results **if** the query was successful.

> *[mysqli_query()] Returns FALSE on failure. For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a mysqli_result object. For other successful queries mysqli_query() will return TRUE.*


> I need help writing something that will make the form to edit the product table.

Alright – check your `$sql` first, and then we can start figuring that out.