takisis Posted July 23, 2015 Share Posted July 23, 2015 (edited) 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 July 23, 2015 by takisis Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted July 23, 2015 Share Posted July 23, 2015 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.) Quote Link to comment Share on other sites More sharing options...
ginerjm Posted July 23, 2015 Share Posted July 23, 2015 Also important - you can't mix the use of mysqli_* functions with MySQL_* functions as you are doing in your dbconnect module and your example code Quote Link to comment Share on other sites More sharing options...
takisis Posted July 23, 2015 Author Share Posted July 23, 2015 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><?phperror_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 Quote Link to comment Share on other sites More sharing options...
takisis Posted July 23, 2015 Author Share Posted July 23, 2015 I got my issues figured out. Thanks for all the help. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted July 23, 2015 Share Posted July 23, 2015 In the future please read the forum rules to see how to properly post code here (and usually in any forum). Makes it easier to read. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.