Trouble displaying Image

A

Anonymous

Guest
Hi
I know I should probably be saving the image to a directory but I am not able to get that to work using godaddy. However I am able to load the image to the database. I can even get the image to display with out my other fields and vice versa. I can display the data from the table but I am not able to get the images and data to display together. Here is my code that I am trying to use.

Code:
<html>
<head>
</head>
<body>
<?php
// Include the database configuration file  
require_once 'con_php.php'; 

//check connection
if ($con -> connect_error){
	die ("connection failed: " . $con -> connect_error);
}

$sql = "SELECT * FROM dish_pic where cat_name = 'Chicken'";

$result = $con ->query($sql);

if ($result-> num_rows >0){
	
	echo "<table><tr><th>Dish Name</th><th>Dish Description</th><th>Dish Size</th><th>Calories</th><th>Total Carbs</th><th>Net Carbs</th><th>Fat</th><th>Fiber</th><th>Protein</th><th>Recommended Side</th><th>Price</th><th></th>";
	while ($row = $result -> fetch_assoc()){
		echo"<tr><td> ". $row["dish_name"] . "</td><td>" . $row["dish_desc"] . "</td><td>" . $row["dish_size"] . "</td><td>" . $row["dish_cal"] . "</td><td>" . $row["dish_tot_carbs"] . "</td><td>" . $row["dish_net_carbs"] . "</td><td>" . $row["dish_fat"] . "</td><td>" . $row["dish_fiber"] . "</td><td>" . $row["dish_protein"] . "</td><td>" . $row["dish_recommend"] . "</td><td>" . $row["price"] . "</td><td> <img src="data:image/jpeg;base64,'.base64_encode($row['name'] ).'" height="200" width="200" class="img-thumnail" /></td></tr>";
	}
	echo"</table>";
}
else { 
	echo"0 results";
}

$con->close();
?>


</body>
</html>

When I do this I am getting the following error.

[01-Apr-2020 02:10:13 UTC] PHP Parse error: syntax error, unexpected 'data' (T_STRING), expecting ',' or ';' in /home/rsv4xn77f3dc/public_html/view_menu.php on line 22
 
You are swapping in and out of double / single quotation marks, meaning that the parser can't work out where your strings begin and end, in line 22.

It's often easier to trace such problems by re-formatting your code rather than having it all on one line; here's an example:
Code:
echo
"<tr><td> " .
$row["dish_name"] .
"</td><td>" .
$row["dish_desc"] .
"</td><td>" .
$row["dish_size"] .
"</td><td>" .
# etc..
formatting like this can make life much easier as it is easier to throw an exit in and see how far you get before it goes wrong if the error doesn't show itself.
 
It shows the data but now it is a broken image where the image should be.

Code:
<html>
<head>
</head>
<body>
<?php
// Include the database configuration file  
require_once 'con_php.php'; 

//check connection
if ($con -> connect_error){
	die ("connection failed: " . $con -> connect_error);
}

$sql = "SELECT * FROM dish_pic where cat_name = 'Chicken'";

$result = $con ->query($sql);

if ($result-> num_rows >0){
	
	echo "<table><tr><th>Dish Name</th><th>Dish Description</th><th>Dish Size</th><th>Calories</th><th>Total Carbs</th><th>Net Carbs</th><th>Fat</th><th>Fiber</th><th>Protein</th><th>Recommended Side</th><th>Price</th><th></th>";
	while ($row = $result -> fetch_assoc()){
		echo"<tr><td> ". $row["dish_name"] . "</td>
		<td>" . $row["dish_desc"] . "</td>
		<td>" . $row["dish_size"] . "</td>
		<td>" . $row["dish_cal"] . "</td>
		<td>" . $row["dish_tot_carbs"] . "</td>
		<td>" . $row["dish_net_carbs"] . "</td>
		<td>" . $row["dish_fat"] . "</td>
		<td>" . $row["dish_fiber"] . "</td>
		<td>" . $row["dish_protein"] . "</td>
		<td>" . $row["dish_recommend"] . "</td>
		<td>" . $row["price"] . "</td>
		<td> 
		<img src=".base64_encode($row["image"])."  height='200' width='200' class='img-thumnail' />
		</td>
		</tr>";
	}
	echo"</table>";
}
else { 
	echo"0 results";
}

$con->close();
?>


</body>
</html>

If you want to see what it is doing here is the link http://ketoworldkitchen.com/view_menu.php
 
I am changing how I am saving the image now. I was able to get the image to save to a folder instead of in the database. I am going to try to see if I can get this way to work.
 
I know I should probably be saving the image to a directory but I am not able to get that to work using godaddy.
What problems are you having?
 
Hi
I was able to figure it out. I am now able to save it to the directory instead of the database. It wasn't doing anything it was showing like it was working but nothing was saving.

Code:
<?php
// Include the database configuration file  
require_once 'con_php.php'; 

//check connection
if ($con -> connect_error){
	die ("connection failed: " . $con -> connect_error);
}

$chsql = "SELECT * FROM dish_pic where cat_name = 'Chicken'";

$chresult = $con ->query($chsql);

if ($chresult-> num_rows >0){
	
	echo "<table><tr><th>Dish Name</th><th>Dish Description</th><th>Dish Size</th><th>Calories</th><th>Total Carbs</th><th>Net Carbs</th><th>Fat</th><th>Fiber</th><th>Protein</th><th>Recommended Side</th><th>Price</th><th></th>";
	while ($row = $chresult -> fetch_assoc()){
		echo"<tr><td> ". $row["dish_name"] . "</td>
		<td>" . $row["dish_desc"] . "</td>
		<td>" . $row["dish_size"] . "</td>
		<td>" . $row["dish_cal"] . "</td>
		<td>" . $row["dish_tot_carbs"] . "</td>
		<td>" . $row["dish_net_carbs"] . "</td>
		<td>" . $row["dish_fat"] . "</td>
		<td>" . $row["dish_fiber"] . "</td>
		<td>" . $row["dish_protein"] . "</td>
		<td>" . $row["dish_recommend"] . "</td>
		<td>" . $row["price"] . "</td>
		<td>
		 <div><img src=\"image/".$row['image_name']."\" height='200' width='200' class='img-thumnail' /></div>
		</td>
		</tr>";
	}
	echo"</table>";
}
else { 
	echo"0 results";
}


?>
 
Back
Top