Showing data from MYSQL with a PHP connection shows nothing

166
January 03, 2018, at 9:13 PM
ob_start();
include("create.php");
ob_end_clean();
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "uploads";
$conn = new mysqli($servername, $username, $password, $dbname);
$sql = "SELECT * from submits (title, description, net)";
foreach ($conn->query($sql) as $row) {
        print $row['title'] . "\t";
        print $row['description'] . "\t";
        print $row['net'] . "\n";
    }

I am trying to get data from the submits table and get title, description and net and echo it out into the page. All the queries into the database are done from create.php. Why is me selecting from the database not printing ANYTHING into the page? (Yes there are things in the database the database is NOT empty.)

Answer 1

Here is what I think should work.
It uses fetch_assoc()

$conn = new mysqli($servername, $username, $password, $dbname);
$sql = "SELECT * from submits (title, description, net)";
$result = $conn->query($sql);
while ($row = $result->fetch_assoc()) {
    print $row['title'] . "\t";
    print $row['description'] . "\t";
    print $row['net'] . "\n";
}
Rent Charter Buses Company
READ ALSO
WooCommerce Print Invoices & Packing Lists change TAX

WooCommerce Print Invoices & Packing Lists change TAX

I work with a old woocommerce version 22

211
PHP preg_match get value of given hidden html form name

PHP preg_match get value of given hidden html form name

I am loading the contents of a URL into a string like this:

294
Sorting dynamically generated html table in modal

Sorting dynamically generated html table in modal

I have searched SO for a similar problem to mine but I can't find anything that would workI have tried a number of different methods with 0 luck

193
Google Maps API marker SVG rendering in Firefox/Edge but not Chrome

Google Maps API marker SVG rendering in Firefox/Edge but not Chrome

My custom SVG with a logo on appears like a regular red dot on Chrome and I have no idea why, but it should be rendering as a logoMozilla Firefox 57

330