How to echo a clickable href to another file in php [closed] - php

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
Im new to php and i am trying study how to design web page, the code is not mine. My problem is , i have some clickable done using a table for that i have an array
$buttons=array('Home'=>'home.php',
'Contact'=>'contact.php',
'Services'=>'service.php',
'Site map'=> 'map.php');
and there is a function
function DisplayMenu($buttons)
{
echo "<table width='100%' bgcolor
='white' cellpadding='4'
cellspacing='4'\n";
echo "<tr>\n";
$width =100/count($buttons);
while (list($name, $url)=each ($buttons))
{
$this-> DisplayButton($width, $name,
$url);
}
echo "</tr>\n";
echo "</table>\n";
}
and for displaying the button there is also a function
function DisplayButton($width, $name, $url)
{
echo " <td width='$width%'>
<a herf ='".$url."'>
<img src= 'ab.jpg' alt='$name'
border='0'>
</a> <a herf='".$url."'><span
class ='menu'>
".$name."</span></a></td>";
}
My problem is when i click for example the home button its not taking me to the home.php page , can someone help me ?

Just a typo (herf to href)
function DisplayButton($width, $name, $url)
{
echo "
<td width='{$width}%'>
<a href='{$url}'>
<img src='ab.jpg' alt='{$name}' border='0'>
</a>
<a href='{$url}'>
<span class='menu'>{$name}</span>
</a>
</td>
";
}

Related

Cannot load a base64 encoded image from mysql database using php [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 months ago.
Improve this question
I have a longblob field in mysql database that stores a binary value for a image that i uploaded through my webpage.
I am trying to get the image using
<?php while( $record = mysqli_fetch_assoc( $result ) ): ?>
<div>
<?php echo '<img src="data:image/jpeg;base64,'.base64_encode($record['image']).'"height="300" width="300"/>'?>
<br/>
<?php echo "Title:".htmlentities( $record['title'] ); ?>
<br/>
<?php echo "Genre:".htmlentities($record['genre']); ?>
<br/>
<?php echo "Author:".htmlentities( $record['author'] ); ?>
<br/>
Edit</i>
<br/>
<a href="books.php?delete=<?php echo $record['id']; ?>"
onclick="javascript:confirm('Are you sure you want to delete this project?');" style="color:#1217b3">Delete</i></a>
</div>
<?php endwhile; ?>
and img tag looks like this in html
<img src="data:image/jpeg;base64,MlN0YXRlLmpwZw==" height="300" width="300">
You have base64 encoded the image file name not the file contents
MlN0YXRlLmpwZw==
actually outputs:
2State.jpg
When storing it in the database you need to do
$imageContent = base64_encode(file_get_contents($file));

PHP - Changing HTML text with variable from MYSQL database [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I'm working on a website and I've got up to a bit now where I want text on the homepage to change, depending on whether or not the user is logged in. Before doing this, I wrapped the text in a div class, which has allowed me to configure how it looks inside a css file. By default, if the user is not logged in, the index.html should display "iBPBuyer, Amazing Deals & Prices." and when the user is logged in, it should then change that text to a simple welcome message, stating their name afterwards, but I cannot seem to get it working.
<?php
require("includes/application_top.php");
require("includes/site_header.php");
require("includes/application_bottom.php");
if($_SESSION['id']) {
echo '<div class="hero-text-box">
<h1>Welcome,<br> $_SESSION['first'].</h1>
</div>
<div class="row">
</div>';
} else {
echo '<div class="hero-text-box">
<h1>iBPBuyer,<br> Amazing Deals & Prices.</h1>
</div>
<div class="row">
</div>';
}
?>
Logged part should be:
echo '<div class="hero-text-box">
<h1>Welcome,<br>' . $_SESSION['first'] . '</h1>
</div>
<div class="row">
</div>';
So, it's just correct concatenation technique.
Simplify your code
$welcome = "iBPBuyer,<br> Amazing Deals & Prices.";
if($_SESSION['id']) {
$welcome = 'Welcome,<br> ' . $_SESSION['first'];
}
echo '<div class="hero-text-box">
<h1>' . $welcome . '</h1>
</div>
<div class="row">
</div>';

Can someone explain this PHP code? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
<h1 class="site-title">
<a href="<?php echo esc_url( home_url( '/' ) ); ?>"
rel="home"><?php bloginfo( 'name' ); ?>
</a>
</h1>
if (is_category('Ponies')) { ?>
// overlay a pretty rainbow on the logo for the ponies category
<img id="rainbow"
src='<?php bloiginfo('template_directory');?>/img/rainbow.png"
alt="OMG! Ponies! " />
<?php } ?>
I'm having trouble matching the PHP tags. The comment for the code says "Now any time the category of the content is Ponies, your header also includes the rainbow.png." But it's clear how that is happening. The actual code is on p245 of WordPress Design and Developement by Williams. Thanks for putting another pair of eyes on it.
"If" is not inside <?php ... ?>. Must be:
<?php if (is_category('Ponies')) { ?>
I prefer to use <?php if (condition): ?> when there's HTML in-between.
But anyhow...
1) The if() statement needs to be inside php tags.
2) You don't need echo to retrieve the bloginfo.
bloginfo() documentation
3) You've misspelled bloginfo at the bottom...
My code:
<h1 class="site-title">
<a href="<?php echo esc_url(home_url('/')); ?>" rel="home">
<?php $bloginfo('name'); ?>
</a>
</h1>
<?php if (is_category('Ponies')) : ?>
<img id="rainbow"
src="<?php get_bloginfo('template_directory') . '/img/rainbow.png'; ?>"
alt="OMG! Ponies!" />
<?php endif; ?>

illegal string offset with while loop [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
<?php
include 'inc/connect.php';
if ($_GET['id'] )
{
$p_id = $_GET["id"];
$query = "SELECT * FROM products WHERE p_id= '$p_id'";
//var_dump($query);
$resu = mysqli_query($con, $query);
while($rs = mysqli_fetch_assoc($resu))
{
?> <img src="<?php echo $p_id['p_image']; ?>" alt="" /> <?php
//var_dump($query);
}
}
?>
this is my code and this is showing me error on my browser what can i do..?
image cant load
Replace this
<img src="<?php echo $rs['p_image']; ?>" alt="" />
to
<img src="<?php echo $p_id['p_image']; ?>" alt="" />

fetch & show images from database with break [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
If i ve inserted images in database in this format
But i want to show the results like this if i m selecting all the images at a time
<?php
$s=mysql_query("SELECT * FROM portfolio");
while($row=mysql_fetch_array($s))
{
?>
<td><img src="portfolio/<?php echo $row['image'];?>" height='100px' width='150px' /></a></td>
After 3 images it should take a break & show in another column ..
any help here.. thankss
I certainly don't recommend you to use mysql* functions. Your HTML had errors too. Why is there "a" close tag when there is no opening tag of a ? I removed it from my answer. Also you didn't had any opeining tr tag or table tag. I added them to the answer.
<?php
echo"<table><tbody><tr>";
$s=mysql_query("SELECT * FROM portfolio");
$k=0;
while($row=mysql_fetch_array($s)){
$k++;
if($k==4){
echo"</tr><tr>";
$k=0;
}
?>
<td><img src="portfolio/<?php echo $row['image'];?>" height='100px' width='150px' /></td>
<?
}
echo"</tr></tbody></table>";
?>
Here's how you do it in PDO :
<?php
echo"<table><tbody><tr>";
$sql=$dbh->prepare("SELECT * FROM portfolio");
$sql->execute();
$k=0;
while($row=$sql->fetch()){
$k++;
if($k==4){
echo"</tr><tr>";
$k=0;
}
?>
<td><img src="portfolio/<?php echo $row['image'];?>" height='100px' width='150px' /></td>
<?
}
echo"</tr></tbody></table>";
?>

Categories