简体   繁体   中英

Printing Query Issue - MySQL, PHP, HTML -

I had a very random problem in an IIS class, it has stumped my tutor so here I am and I'll try my best to explain it well!

I'm running Xampp with Apache and MySQL, I run the query I want and get the expected output to a table, but I have a problem with the outputting of pictures. I have the right file type, extention and path selected, because I can get pictures to show up, but as long as at least one picture in the query result has the extension removed, and this picture will not load.

Database

在此处输入图片说明

Website

在此处输入图片说明

If I have each query result with the correct name and extension, which is the same as when it shows up, none of them show up at all!

PHP:

<?php 

// set server access variables 
  include 'db2.inc';

// open connection 
$connection = mysql_connect($hostname, $username, $password) or die ("Unable             to connect!"); 

// select database 
mysql_select_db($databaseName) or die ("Unable to select database!"); 

// create query 
//$query = "SELECT * FROM products"; 
$query = "SELECT * FROM products WHERE CategoryName = 'Surfboards'"; 
//Check initial letter
//if (!$initialLetter=="")
//{ 
//  $query = $query." Where country like  '$initialLetter%' ";
//}

// execute query 
$result = mysql_query($query) or die ("Error in query: $query.     ".mysql_error()); 

// see if any rows were returned 
if (mysql_num_rows($result) > 0) { 
// yes 
// print them one after another 
echo "<table cellpadding=20 border=1>"; 
while($row = mysql_fetch_assoc($result)) { 
    echo "<tr>"; 
    echo "<td>".$row['ProductID']."</td>"; 
    echo "<td>".$row['Name']."</td>"; 
    echo "<td>".$row['Description']."</td>"; 
    echo "<td>".$row['Brand']."</td>"; 
    echo "<td>".$row['Model']."</td>"; 
    echo "<td>".$row['BoardLength']."</td>"; 
    echo "<td>".$row['BoardType']."</td>"; 
    echo "<td>".$row['Colour']."</td>"; 
    echo "<td>"."<img src=images/".$row['Image']."> </td>";
    echo "<td>".$row['UnitPrice']."</td>"; 
    echo "<td>".$row['CategoryName']."</td>"; 
    echo "</tr>"; 
} 
echo "</table>"; 
} 
else { 
// no 
// print status message 
echo "No rows found!"; 
} 

// free result set memory 
mysql_free_result($result); 

// close connection 
mysql_close($connection); 

?> 

Any help or direction would be greatly appreciated!

Thanks

Will

On this line:

echo "<td>"."<img src=images/".$row['Image']."> </td>";

Your image src is not enclosed in quotes. If this is a direct copy/paste of your code then that is definitely a problem, but may not be the only one.

As other people have said, look at pdo, or mysqli. The mysql_ functions you are using are deprecated for multiple reasons.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM