png image saved in mysql database, doesn't fully show on browser - php

PHP codes of index.php
<?php
include("connection.php");
$sql = "SELECT prod_cost, prod_name, prod_image FROM products";
$result = mysqli_query($con, $sql);
$row = mysqli_fetch_all($result, MYSQLI_ASSOC);
//free result from memory
mysqli_free_result($result);
//close connection
mysqli_close($con);
?>
image is read in src"" on the second line of the snippet below. Everything works but only half the image shows.
<div class="col-1" onclick="location.href='item1.html';" style="cursor: pointer;">
<img src="data:image/ppg;charset=utf8;base64,<?php echo base64_encode($row[0]['prod_image'])?> " alt="Rooster Chicken #18">
<h4><?php echo $row[0]['prod_name']; ?></h4>
<p>$ <?php echo $row[0]['prod_cost']; ?> <strike> $17.80 </strike></p>
</div>
The image was added directly to the database with
INSERT INTO products(prod_name, prod_stock,prod_cost,prod_image)
VALUES ('Rooster Chicken #18',100,17.65,LOAD_FILE('C:/xampp/htdocs/SNS/Images/products/rooster18.png'));
NB: PHP snippets shown above are from the same page called index,php

Verify your data type for prod_image column. Make sure what you save via LOAD_FILE('C:/xampp/htdocs/SNS/Images/products/rooster18.png') has enough space/size to store the complete image. I've used your code and it is working fine in my side(please change data:image/ppg to data:image/png).
FYI below table structure is used:

Related

Click on an image stored in a MySQL database table and get additional row content for that image

I have created a members.php page that connects to a database table. The table has the following fields: id, username, profile image.
The following PHP code displays the profile image for each user in rows of 6 and allows each image to be clickable.
<?php
// The code below will display the current users who have created accounts with: **datemeafterdark.com**
$result=mysql_query("SELECT * FROM profile_aboutyou");
$row1 = mysql_fetch_assoc($result);
$id = $row1["id"];
$_SESSION['id'] = $id;
$profileimagepath = $row1["profileimagepath"];
$_SESSION['profileimagepath'] = $profileimagepath;
$count = 0;
while($dispImg=mysql_fetch_array($result))
{
if($count==6) //6 images per row
{
print "</tr>";
$count = 0;
}
if($count==0)
print "<tr>";
print "<td>";
?>
<center>
<img src="<?php echo $dispImg['profileimagepath'];?>" width="85px;" height="85px;">
</center>
<?php
$count++;
print "</td>";
}
if($count>0)
print "</tr>";
?>
This is all great, however, when I click on the image that loads it re-directs me to: viewmemberprofile.php which is what it is supposed to do. But it always displays the same image with the same id value (i.e.) 150 no matter which image I click. What I would like to have happened is. If I click on an image with id 155 etc... it will display content for that image data field not consistently the same image data regardless of which image I click.
Your help and guidance would be greatly appreciated. Thank you in advance.
One thing that I forgot to mention is that I do use sessions so... when I am re-directed to the viewmemberprofile.php page I use the following code to aide in getting the data that I need from the table.
<?php
$id = $_SESSION['id'];
echo($id);
?>
<?php
echo('<br>');
?>
<?php
$profileimagepath = $_SESSION['profileimagepath'];
?>
<img src="<?php echo($profileimagepath);?>" width="50px;" height="50px;">
I have yet to impliment the suggested solution.
You need to pass the ID of the row to viewmemberprofile.php, e.g.:
<a href="viewmemberprofile.php?id=<?= $dispImg['profileimagepath'] ?>">
And viewmemberprofile.php needs to select that row from the DB:
SELECT * FROM profile_aboutyou WHERE id = $_GET['id']
The above SQL statement is pseudo-code; you need to write actual code to accomplish what it is describing, preferably using parameterized queries.

How to generate a PDF with multiple page breaks?

I want to create a PDF using HTML, PHP, and MySQL and I want a new page every time a new row is fetched and then generate a combined PDF for all the pages created.
How can I achieve this?
<?php
$count=0;
$con = mysqli_connect("localhost","root","");
mysqli_select_db($con, "electricity");
$result = mysqli_query($con, "SELECT acct, name, address, amount FROM newtable");
while($row = mysqli_fetch_array($result))
{
?>
<html>
<body><pre>
श्री: <?php echo $row['name'];?><br>
पता: <?php echo $row['address'];?>
ACCNO :- <b><?php echo $row['acct'];?></b>
Amount : <b><?php $val=$row['amount']+25; echo $val;?></b>
</pre>
</body>
</html>
<?php
}
mysqli_close($con);
?>
I used FPDF many times and it allows you to do whatever you want. Have more info here for doc & download link : http://www.fpdf.org/?lang=en

php mySQL how to show images, problems on img src

I've been working on this for four hours and I still have no clue, so I came here to seek help. I'm learning PHP and mySQL and one of the way I learn is to learn from open source projects. Today I'm trying to understand an open source project and I have some problems. Here is the link to the open source project: https://github.com/markpytel/Printstagram Basically, it has something like the following, let's call it profileinfo.php (name of this file is pretty deceiving, it is a page that shows images uploaded by different users)
<?php
$sql="SELECT pid,poster, pdate FROM photo WHERE poster='$myusername' OR pid
in (select pid from tag where taggee='$myusername') OR pid in (select pid
from ingroup natural join shared where username='$myusername' and username
!= ownername) ORDER BY pdate desc";
$result=mysql_query($sql);
while($row = mysql_fetch_array($result))
{
echo "<hr>";
echo "Posted by: " . $row["poster"]. " Time: " . $row["pdate"]."<br>";
// pid is each photo's unique id in the database
$pidrow=($row["pid"]);
?>
</head>
<body>
<form action="listsingleREV.php?pidrow=<?php echo $pidrow; ?>" method="POST">
<input type="submit" id="pidrow" value="View this image" />
</form>
</body>
</html>
If you click on the button that says "view this image", image uploaded by users will appear. The first question I have is: What's the meaning of the question mark in the image src. I understand that there is a PHP tag in the img src, but I don't understand why there is a question mark between listsingleREV.php and pidrow.
listsingleREV.php looks like this:
<?php
session_start();
$pidrow=$_GET['pidrow'];
$conn = mysql_connect("localhost", "root", "");
mysql_select_db("printstagram");
$sql = "SELECT pid FROM photo WHERE pid=$pidrow";
$result = mysql_query($sql);
?>
<?php
while($row = mysql_fetch_array($result)) {
?>
<img src="imageview.php?pid=<?php echo $row["pid"]; ?>" /><br/>
<?php
}
?>
imageview.php looks like this:
<?php
$conn = mysql_connect("localhost", "root", "");
mysql_select_db("printstagram") or die(mysql_error());
if(isset($_GET['pid'])) {
$sql = "SELECT image FROM photo WHERE pid=" . $_GET['pid'];
$result = mysql_query("$sql") or die("<b>Error:</b> Problem on Retrieving Image BLOB<br/>" . mysql_error());
$row = mysql_fetch_array($result);
header("content-type: image/jpeg");
echo $row["image"];
}
mysql_close($conn);
?>
Of course, if a user has to click on a button to see each image, it is very inconvenient. So I decide to give myself some practice and modify the code(it is Apache license so I can do it)such that images will be automatically presented on profileinfo.php without the need to click on a button. Since imageview.php and listsingleREV.php show the images, I tried to substitute the form in profileinfo.php with these two files. I worked on it for four hours without achieving my goal. Can someone tell me the correct way to show the images on profileinfo.php without the need to click on the button?
As it appears in imageview.pho the $row[pid] contain the link of your image in photo table so add this line to profileinfo.php under the while loop in the place you want it to display
<img src="<?php echo". $row["pid"]."; ?>">

image display, php mysql

I'm developing a project Personl and I have encountered a problem.
Details my of problem
Perform a query via a form, which calls me to another page where the query is displayed, everything is correct, it displays the information that I need, but when viewing the user's image, calling me by request the ID corresponding to this user, but not my image code is displayed below.
Code to display the image in html:
<img src="../../registro/imagen.php?matricula=<?php echo $_POST['matricula']; ?>" width="150px" height="150px" />
Code search the image by id to display:
<?php
$numero=$_REQUEST['matricula'];
$tabla="alumno";
include("../../Connections/colegio.php");
$conexion=#mysqli_connect($hostname_colegio,$username_colegio,$password_colegio,$database_colegio);
$sacar = "SELECT * FROM ".$tabla." WHERE (matricula=$numero)" ;
$resultado = mysqli_query($conexion,$sacar);
while ($registro = mysqli_fetch_assoc($resultado))echo mysqli_error( $conexion );{
$tipo_foto=$registro['matricula'];
header("Content-type: image/jpg");
echo $registro['matricula'];
}
mysqli_close($conexion);
?>
may terminate this issue, if it helps someone, I leave the correct code.
<?php
$numero=$_REQUEST['matricula'];
$consulta="select * from alumno WHERE (matricula = $numero)";
$busca_fotos=mysql_query($consulta) or die("Error en: $busca_fotos:" .mysql_error()) ;
while($ro=mysql_fetch_assoc($busca_fotos)){
$url=$ro['matricula'];
echo "
<img src=\"../../registro/fotos/".$url.".jpg\" width=\"150\" height=\"150\" alt=\"\" />
</a>
";
}
?>

positioning data on your webpage pulled from a mysql database

I am trying to position the data pulled from my mysql database using the following php code on my webpage;
<?php
require "connect.php";
$query = "select * from item LIMIT 0, 1";
$result = #mysql_query($query, $connection)
or die ("Unable to perform query<br>$query");
?>
<?php
while($row= mysql_fetch_array($result))
{
?
//call each item from the database, and nest in div or html table
<?=$row['item']?>
<?=$row['description']?>
<?=$row['brand']?>
When I view the webpage it creates the row for each item however each field is empty?
The conection to the database is fine as I ran another piece of code which simply displayed all the info in 1 block. However this is not what I want I want to be able to position each item where I want it on the site.
I wrote this when I had php version 4.1 running on IIS I am now running the latest version of php 5 and after doing some reading it says there are chnages in the syntax including global variables disabled by default so not sure if this is the issue?
try:
<?php echo $row['item'] ?>
<?php echo $row['description'] ?>
<?php echo $row['brand'] ?>
I believe the <?= ?> syntax is normally disabled by default.
The following will also show a dump of you $row array, so you can make sure that it actually contains data
<?php print_r($row); ?>
Good luck!
Sorttag maybe no enabled, try :
<?php echo $row['item']; ?>
<?php echo $row['description']; ?>
<?php echo $row['brand']; ?>

Categories