How to echo mysqli_query result
I'm making a personal script for my own use, and I need to know how to echo the results from a mysqli_query. My code is as follows: Show
Dharman♦ 27.8k21 gold badges75 silver badges127 bronze badges asked Apr 21, 2015 at 19:33
10 If you want to output multiple rows
If only 1 row
Dharman♦ 27.8k21 gold badges75 silver badges127 bronze badges answered Apr 21, 2015 at 19:42
KristapsvKristapsv 5585 silver badges15 bronze badges 1 First of all as @fred-ii said, escape your post, there is also an error in your $_POST access, you are missing quotes around article key, and lastly use mysqli_fetch_assoc to acces your results:
answered Apr 21, 2015 at 19:47
You can simply loop on the result object with
However, in your case you should not be
using For example your fixed query would look like this:
The difference is that my variable is not separate from the SQL, so there is no risk of injection. You should never allow any variable input directly in SQL query. Doing this properly is really not that difficult. Also, you don't really need to repeat the code so much. You can
parameterize answered Feb 16, 2020 at 15:46
Dharman♦Dharman 27.8k21 gold badges75 silver badges127 bronze badges What is the result of mysqli_query?For successful queries which produce a result set, such as SELECT, SHOW, DESCRIBE or EXPLAIN , mysqli_query() will return a mysqli_result object. For other successful queries, mysqli_query() will return true .
How many parameters does the mysqli_query () function accept?PHP uses mysqli query() or mysql_query() function to create or delete a MySQL database. This function takes two parameters and returns TRUE on success or FALSE on failure.
How do you retrieve data from database in PHP using MySQLi?Connecting to a Database:. MySQLi Object-Oriented $conn = new mysqli($servername, $username, $databasename). MySQLi Procedural $conn = mysqli_connect($servername, $username, $password, $databasename);. PDO. $conn = new PDO("mysql:host=$servername;dbname=myDB", $username, $password, $databasename);. What is MySQLi fetch?Definition and Usage. The fetch_array() / mysqli_fetch_array() function fetches a result row as an associative array, a numeric array, or both.
|