Home MySQL query not outputting result only heading
Reply: 0

MySQL query not outputting result only heading

user1515 Published in March 24, 2018, 12:45 am

I am currently practicing PHP and AJAX and I am trying to create an application that allows a user to search a database for product stock in real time. When the user types in a letter within one of the entries the headings show up but not the data. I'm not sure if I am doing it wrong but I'll let you guys be the judge of that. Code below:

Results.php - Below

 <!DOCTYPE html>
<link rel="stylesheet" type="text/css" href="style.css">

$q = intval($_GET['q']);

$con = mysqli_connect("localhost", "username", "password", "databaseName");
//edited out for safety 

if (!$con) {
die('Could not connect: ' . mysqli_error($con));


$sql="SELECT * FROM stock WHERE name LIKE '%{$q}%'";
$result = mysqli_query($con,$sql);

echo "<table>
<th>Product name</th>

if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
echo "<tr>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['descr'] . "</td>";
echo "<td>" . $row['price'] . "</td>";
echo "<td>" . $row['quantity'] . "</td>";
echo "</tr>";

echo "</table>";

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.298528 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO