Issue with photo echo in php, simple task - php

i have this code in php and it's supposed to print me the image but it isn't.
Is there any problem with this code?
Thanks!
echo "<td> <img src=foto/photo1/".$row['photo'] . "
></td>";
echo "<td> <img src=foto/photo2/".$row['photo2'] . "></td>";

You have missed the ' marks in the echo. Try this:
echo '<td> <img src="foto/photo1/'.$row['photo'].'"></td>';
echo '<td> <img src="foto/photo2/'.$row['photo2'].'"></td>';

Use single quotes ' for image src attribute.
Change your code like this
<img src='foto/photo1/".$row['photo'] ."'></td>

Related

Image and words with classes won't display (PHP CSS HTML)

Got problem displaying the below picture and words, what am I doing wrong?
echo "<img src="images/<?php echo $row["image"]; ?>" class="img-responsive" /><br />";
echo "<h4 class="text-info"><?php echo $row["name"]; ?></h4>";
AS you are working in php so you have no need to echo <?php echo $row["image"]; ?> in side an echo and you have to consider about single quotes and double quotes
Do like this
echo "<img src='images/".$row["image"]."' class='img-responsive' /><br />";
echo "<h4 class='text-info'>".$row["name"]."</h4>";
At first you need to use php tag for translating echo tag after do like this..
<?php
echo '<img src="images/echo $row["image"];" class="img-responsive" /><br/>';
echo '<h4 class="text-info"> echo $row["name"]; </h4>';
?>
try this.
echo "<img src='images/'". $row['image']." class='img-responsive' /><br />";
echo "<h4 class='text-info'>".$row['name']."</h4>";

replace edit and delete with icon

i need to change the edit and delete button on this table with icons
im trying too much with 500 error :(
echo "<tr>";
echo "<td>{$userSet['user_id']}</td>";
echo "<td>{$userSet['username']}</td>";
echo "<td>{$userSet['password']}</td>";
echo "<td><a href='delete_user.php?user_id={$userSet['user_id']}'>Delete</a></td>";
echo "<td><a href='edit_user.php?user_id={$userSet['user_id']}'>Edit</a></td>";
echo "</tr>";
Put img tag inside the a href attribute.
echo "<td><a href='delete_user.php?user_id={$userSet['user_id']}'><img src='path/to/img'></a></td>";
echo "<td><a href='edit_user.php?user_id={$userSet['user_id']}'><img src='path/to/img'></a></td>";

Outputting PHP within a HTML tag in PHP

Kind of stuck on this one issue, tried all the ways of outputting regular HTML in PHP which works fine, but when trying get PHP code and then making that into HTML link where everything is in PHP. Line 17 & 18 is the issue, this maybe very simple to someone, but its proven difficult for me :(
Any help is much appreciated. Thanks in advance
<?php
if($output == true) {
echo "<td>".$id."</td>";
echo "<td>".$fname."</td>";
echo "<td>".$lname."</td>";
echo "<td>".$dob."</td>";
echo "<td>".$gender."</td>";
echo "<td>".$hnumber."</td>";
echo "<td>".$mnumber."</td>";
echo "<td>".$email."</td>";
echo "<td>".$username."</td>";
echo "<td>".$address."</td>";
echo "<td>".$type."</td>";
echo "<td><a href='memberdelete.php?id=".$rows['ID']."'>Delete</a></td>"; echo "<td><a href='memberedit.php?id=".$rows['ID']."'>Edit</a></td>";
echo "</tr>";
echo "</table>";
}
?>
Change it to,
echo "<td><a href='memberdelete.php?id=".$rows['ID']."'>Delete</a></td>";
Useful: How strings work in PHP ?
Try this, I wrote it quickly, hope it work:
echo '<td>Delete</td>';
echo '<td>Edit</td>';
Horrible enclosing of quotes and multiple echo on same line was your problem.
Update to:
echo "<td><a href='memberdelete.php?id=".$rows['ID']."'>Delete</a></td>";
echo "<td><a href='memberedit.php?id=".$rows['ID']."'>Edit</a></td>";
You can do this for the above code:
<?php
if($output == true) {
echo "<td>".$id."</td>";
echo "<td>".$fname."</td>";
echo "<td>".$lname."</td>";
echo "<td>".$dob."</td>";
echo "<td>".$gender."</td>";
echo "<td>".$hnumber."</td>";
echo "<td>".$mnumber."</td>";
echo "<td>".$email."</td>";
echo "<td>".$username."</td>";
echo "<td>".$address."</td>";
echo "<td>".$type."</td>";
echo "<td><a href='memberdelete.php?id=".$rows['ID']."'>Delete</a></td>";
echo "<td><a href='memberedit.php?id=".$rows['ID']."'>Edit</a></td>";
echo "</tr>";
echo "</table>";
}
?>
You have misplaced the quotes and html tags.so
change
echo "<td>".Delete."</td>";
echo "<td>".<a href="memberedit.php<?php echo '?id='.$rows['ID']; ?>"
to
echo "<td><a href='memberdelete.php?id=$rows[ID]'>Delete</a></td>";
echo "<td><a href='memberedit.php'?id='$rows[ID]'>Edit</a></td>";
If you have problem with quotes and assigning values to parameters inside quotes try HEREDOC
You have incorrect strings.
changes those lines:
echo "<td>".Delete."</td>";
echo "<td>".<a href="memberedit.php<?php echo '?id='.$rows['ID']; ?>"
to:
echo "<td>Delete</td>";
echo "<td><a href=\"memberedit.php<?php echo '?id='.$rows['ID']; ?> </td>"

how to apply bgcolor in table using echo command

I want to apply background colour to a table. I have written table using echo command , but am confused about how to apply bgcolor can any one guide me..
print("<table align='center' width='50%' border=1> ");
echo "<TR><TD> Sr.No </td>";
echo "<td width=\"16%\" bgcolor=\"#CCCCCC\"> delete</td>";
echo "<Td> File Name </td> ";
echo "<td> Share It </td>";
echo "</tr></table>";
echo '<tr><td> Sr.No</td>';
echo '<td width="16%" bgcolor="' . $colorVariable . '"> delete</td>';
echo '<td> File Name </td>';
echo '<td> Share It</td></tr>';
The "'s are colliding. You need to escape the character, like below.
echo"<td width=\"16%\" bgcolor=\"#CCCCCC\"> delete</td>";
try
echo '<td width="16%" bgcolor="#CCCCCC"> delete</td>';
PHP double quote and single quote
$some="Oh god";
echo "My answer is $some ";
//result is: My answer is Oh god
In the above, using double quotes, the variable $someis evaluated within the quotes and the result isn't what is expected: the variable is evaluated to Oh god. Variables, but not functions or constants, are evaluated even when enclosed in double quotes.
echo 'My answer is $some';
//result is: My answer is $some.
When single quotes are used, as above, the variable isn't evaluated and is printed on the screen literally as $some.
good read
Is there a performance benefit single quote vs double quote in php?

Concatenating In PHP

What is the proper way to write the following code?
echo '<img src="'images/.$row['picture']. '"/>';
I want to display an image from the database.
If I understand the question correctly,
<?php
echo '<img src="/images/' . $row['picture'] . '"/>';
?>
or
<?php
echo "<img src='/images/" . $row['picture'] . "'/>";
?>
You can use vprintf function: http://www.php.net/manual/ru/function.vprintf.php
vprintf('<img src="images/%s"/>', $row['picture']);
Or this:
echo "<img src=\"{$row['picture']}\" />";
Don't forget to escape html characters: http://php.net/manual/en/function.htmlspecialchars.php
$row['picture'] = htmlspecialchars($row['picture'], ENT_QUOTES);
echo '<img src="images/'.$row['picture'].'" />';
Try
<?php
echo "<img src=images/".$row['picture']."/>";
?>
echo '<img src=images/'.$row['picture'].'>';

Categories