Skip to content
Advertisement

My php code won’t show back result form phpmyadmin (sql) database

So i recently set up a local web server on Raspberry Pi and I am currently experiencing little bit of trouble. I wrote a code (for test reasons) that after you click on one button in .html it runs test.php document that creates a table in sql, fills in the data and than prints the output.

Everything goes as planed till part when php should return/echo $row but it doesn’t its just empty space.

Advertisement

Answer

I believe your issue is that you executed $result=mysqli_query($conn,$query); before the table was created in the DB. The query is executed when you call it. The mysqli_fetch_array just “transforms” a previous result row to an array format.

Try executing mysqli_query($conn,$query) right before the while.

I suggest also you define value for the mysqli_fetch_array second argument $resulttype (optional).

See docs for reference: https://www.php.net/manual/en/mysqli-result.fetch-array.php

Default value (MYSQLI_BOTH) is usually an overkill and apparently you just want the result format that comes from using MYSQLI_ASSOC.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement