image display, php mysql - php

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

Related

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

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:

how to display a photo from database base on its id to another page

I have a huge problem and been having a hard time figuring it out.I want to pass down the image id i click on onto the 2nd page.The 2nd page then uses the id and echos out an image,image_text based on what i gave in the database.
1st page
while ($row = mysqli_fetch_assoc($result)) {
echo "<div class='img-single'>
<a href='images/fpage.php?image_id={$row['image_id']}'><img class='i'
src='images/".$row['image']."' ></a>
<figcaption class='figcaption'>".$row['image_text']."</figcaption>
</div>";
}
?>
2nd page
<?php
$image_id = $_GET['image_id'];
?>
So after passing the image id in a a href='somepage.php&image_id=$image' tag. On the 2nd page use: if (isset($_GET['image_id'])) { $pic_id = $_GET['image_id'] Then make a select from database using pic_idmysqli_query($dbc, "SELECT picture, name from table_name WHERE picture_id = '$pic_id' LIMIT 1;"); echo the picture in image tags and your done.
<img src="<?php echo $picture; ?>" alt="<?php echo $name; ?>">} // Close if(issset()) I hope this helps.

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"]."; ?>">

No images displayed on the page after querying the database PHP mysql

This is my first post on stackoverflow after following posts for a very long time.
My problem is, I have a function that is supposed to retrieve data from a table (models) and display a name, location and an image to one of the pages. Everything is working but the images don't get displayed. Please look at my code and tell me what I should change to get these images to display. I'm using twitter bootstrap for styling.
My directory is: localhost/mainsite/admin/uploads
I've checked everything related to this post and tried it out but they didn't solve my problem. So please help.
function view_models() {
global $dbc;
$q = "SELECT * FROM models";
$r = mysqli_query($dbc, $q);
while ($row = # mysqli_fetch_array($r)) {
$id = $row['model_id'];
$mn = $row['model_name'];
$ln = $row['location'];
$img = $row['image1'];
echo "
<div class='col-xs-6 col-lg-3'>
<h3>$mn</h3>
<a href='details.php?id=$id'>
<img src='admin/uploads/$img' class='img-thumbnail' />
<p>$ln</p>
</div>";
}
}
Try this.,
I have changed the echo statement because you did a error, that was misplaced '&"
echo "<div class='col-xs-6 col-lg-3'>
<h3>".$mn."</h3>
<a href='details.php?id=".$id."'>
<img src='admin/uploads/".$img."' class='img-thumbnail' />
<p>".$ln."</p>
</a>
</div>";

php display image

I am not able to display image using this code. Could any one help me in correcting?
<?php
include("connect.php");
$sql="select * from profile where userid=3";
$row=mysql_query($sql);
header("Content-type: image/jpeg");
echo $row['image'];
?>
Try
<?php
include("connect.php");
$sql = "SELECT * FROM profile WHERE userid='3'";
$row = mysql_fetch_assoc(mysql_query($sql));
echo '<img src="'.$row['image'].'" />';
?>
Depends how your information is stored in the database. If you have stored the path to a picture, this will be the right way. If you have stored the whole picture, this must be done another way.
Have you tried this way:-
echo "<img src=\"".$row['image']."\">";

Categories