Trouble displaying Image

images php coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
Icewolf0927
New php-forum User
New php-forum User
Posts: 5
Joined: Tue Mar 31, 2020 6:03 pm

Tue Mar 31, 2020 6:11 pm

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: Select all

<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
User avatar
hyper
php-forum GURU
php-forum GURU
Posts: 1222
Joined: Mon Feb 22, 2016 5:52 pm

Wed Apr 01, 2020 8:02 am

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: Select all

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.
Icewolf0927
New php-forum User
New php-forum User
Posts: 5
Joined: Tue Mar 31, 2020 6:03 pm

Wed Apr 01, 2020 3:47 pm

thanks that make sense. I will try that.
Icewolf0927
New php-forum User
New php-forum User
Posts: 5
Joined: Tue Mar 31, 2020 6:03 pm

Wed Apr 01, 2020 5:49 pm

It shows the data but now it is a broken image where the image should be.

Code: Select all

<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
Icewolf0927
New php-forum User
New php-forum User
Posts: 5
Joined: Tue Mar 31, 2020 6:03 pm

Wed Apr 01, 2020 7:05 pm

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.
User avatar
hyper
php-forum GURU
php-forum GURU
Posts: 1222
Joined: Mon Feb 22, 2016 5:52 pm

Thu Apr 02, 2020 7:26 am

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?
Icewolf0927
New php-forum User
New php-forum User
Posts: 5
Joined: Tue Mar 31, 2020 6:03 pm

Sat Apr 04, 2020 9:14 am

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: Select all

<?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";
}


?>
Post Reply