Jump to content

Webpage not display info from mysql database


takisis

Recommended Posts

I have written a page to display vehicles for sale with a picture, year, make, model and price of vehicle.  There is no syntax errors in the code and when I run the code It displays nothing.  My code is listed below.  Please help.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Inventory</title>
<style>
table {
    font-family:Verdana, Geneva, sans-serif;
    font-size:12px;
    font-weight:bold;
    color:#FFF;
}
</style>
</head>

<body background="images/bg-image1.jpg">
<p align="center" style="font-family:Verdana, Geneva, sans-serif; color:#FFF; font-weight:bold"><font size="5">Vehicles for Sale</font><br /><font size="2">(All photos are file photos<br />Photos do not represent actual vehicles)</font></p>
<?php
    include_once('dbconnect.php');

$q = "SELECT * FROM vehicles";
$r = mysqli_query($q);
    
echo "<table align='center' width='990' class='table'>
<tr>
<th>Picture</th>
<th>Year</th>
<th>Make</th>
<th>Model</th>
<th>Price</th>
</tr>";
while($row = mysqli_fetch_array($r)){

echo "<tr>";
echo "<td width='203'>";
echo "<img src='data:image/jpeg;base64,".base64_encode($row['image'])."'>";
echo "</td>";
echo "<td>" .$row['year']. "</td>";
echo "<td>" .$row['make']. "</td>";
echo "<td>" .$row['model']. "</td>";
echo "<td>" .$row['price']. "</td>";
echo "</tr>";
echo "</table>";
}
?>
</body>
</html>
 

Code from dbconnect.php:

 

<?php
  mysqli_connect("localhost", "takisis", "zifnab#666") or die(mysqli_error());
  mysqli_select_db("ezwayautos") or die(mysqli_error());
?>

Edited by takisis
Link to comment
Share on other sites

do you have php's error_reporting set to E_ALL and display_errors set to ON so that php would help you by reporting and displaying all the errors it detects?

 

next, you cannot use mysqli_error() to display mysqli_connect() errors, because msyqli_error(...) requires the connection as a parameter. you must use mysqli_connect_error() to display mysqli_connect() errors.

 

lastly, you should always test if your database queries ran without any errors (display a user error message and display/log for development/live server the actual error information) and for queries that may match zero rows, test if the query matched any row and output a user message if it doesn't (sorry, no data was found.)

Link to comment
Share on other sites

Ok I now have the data displaying from the database.  Thanks for the help.  I need to get it to format so that one listing is right below the last in my table.  Here is the new code so that you can see what is changed.  I will also attach the file so that you can run it and give me suggestions.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Inventory</title>
<style>
table {
    font-family:Verdana, Geneva, sans-serif;
    font-size:12px;
    font-weight:bold;
    color:#FFF;
}
</style>
</head>

<body background="images/bg-image1.jpg">
<p align="center" style="font-family:Verdana, Geneva, sans-serif; color:#FFF; font-weight:bold"><font size="5">Vehicles for Sale</font><br /><font size="2">(All photos are file photos<br />Photos do not represent the actual vehicles)</font></p>
<?php
error_reporting(E_ALL);

$dbhost = 'localhost';
$dbuser = 'takisis';
$dbpass = 'zifnab#666';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
  die('Could not connect: ' . mysql_error());
}

$sql = "SELECT * FROM vehicles";

mysql_select_db('ezwayautos');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('Could not get data: ' . mysql_error());
}
    
echo "<table align='center' width='990' class='table'>
<tr>
<th>Picture</th>
<th>Year</th>
<th>Make</th>
<th>Model</th>
<th>Price</th>
</tr>";
while($row = mysql_fetch_assoc($retval))
{

echo "<tr>";
echo "<td>";
echo "<img src='data:image/jpeg;base64,".base64_encode($row['image'])."'>";
echo "</td>";
echo "<td>" .$row['year']. "</td>";
echo "<td>" .$row['make']. "</td>";
echo "<td>" .$row['model']. "</td>";
echo "<td>" .$row['price']. "</td>";
echo "</tr>";
echo "</table>";
}
?>
</body>
</html>

inventory.php

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.