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"]."; ?>">
Related
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.
using external web pages customers can create a ticket with different values and upload images. All these values are passed to an internal system that allows people to manage the tickets but are shown only the database values and not the images on a simple php page. When a ticket is created the ticket and the images folder (that is automatically created) share a common and unique ID. So the ticket is the same as the folder name.Searching for the ID the pages with all the data is shown using this:
<?php
$link = mysqli_connect("xxx", "xxx", "xxx", "xxx");
if($link === false){
die("ERRORE: DB error. " . mysqli_connect_error());
}
$num = $_GET['ticket_id'];
$query = "SELECT * FROM tickets WHERE ticket_id = '$num'";
$result = mysqli_query($link,$query);
$row = mysqli_fetch_array($result);
?>
<form action="edit.php" method="post">
<table id="myTable">
etc
I tried using something like glob function but I always get "no images to display"
<?php $thumbs = glob("2021/ticket_att/$num/*.{jpg,jpeg,png,gif}", GLOB_BRACE)?>
<?php
if(count($thumbs)) {
natcasesort($thumbs);
foreach($thumbs as $thumb) {
?>
<li>
<img src="<?php echo $thumb ?>" width="50%" alt="ticket image" />
</li>
<?php
}} else {
echo "No images to display!";
}
?>
Where am I getting wrong?
Thank you!
--> UPDATE <--
The glob function works if I change the value of $num into a fixed value (for example
<?php $thumbs = glob("2021/ticket_att/123456/*.{jpg,jpeg,png,gif}", GLOB_BRACE)?>
but if I check the value of $num is correct. Maybe the functions doesnt' read a variable value?
Thanks!
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>
";
}
?>
SOLVED!
so ive created an image upload page which saves the image to a folder and sends the file name to the DB, ive checked to see if they are actually being added to the DB and folder which they are, but when i call the data to another page to display the images i get broken images.
below is my code to call the images, its some code ive scraped together from various tutorials as they gave me the same problem as im having now.
UPDATE:
ive managed to get the images showing but now im faced with being shown the same image for each row of data called, the id and img_name and right for each row but the image is always the same as the first listed.
UPDATED CODE:
<?php
//connect to database
include ('connect.php');
//save the name of image in table
$query = mysql_query("select * from tbl_img") or die(mysql_error());
//retrieve all image from database and store them in a variable
while ($row = mysql_fetch_assoc($query))
{
$img_name = $row['img'];
}
?>
<?php
include ('connect.php');
$img_id = mysql_query("SELECT * FROM tbl_img");
while ($row = mysql_fetch_assoc($img_id))
{
$id = $row['img_id'];
echo "
$id<br>
$img_name<br>
<img src='http://localhost/testarea/include/site_images/$img_name' />
";
echo "<br><br><br></p>
";
}
?>
If you start the path of image with / you mean an absolute path where / is the DocumentRoot folder (or the directory of virtualhost)
With src ="includes/xxx/image.png" you mean that includes is in the same folder with the php script. If it is not you can use relative path like
src="../includes/xxx/image.png" for example
<?php
include ('connect.php');
$img_id = mysql_query("SELECT * FROM tbl_img");
while ($row = mysql_fetch_assoc($img_id))
{
$img_name = $row['img'];
$id = $row['img_id'];
echo "
$id<br>
$img_name<br>
<img src='http://localhost/testarea/include/site_images/$img_name' />
";
echo "<br><br><br></p>
";
}
Hey all I have a table caleld Box1, with a simple structure of: id(increment,primary) imageurl, link.
What I am looking to do, is on my site in the HTML file, display the imageurl into a imgsrc, so that the Image URL loads the image when going to the site
I cannot find specifically what I am looking for online and know I must be close somewhere, this is what I have so far in my coding for my .php file.... thanks.
<?php
$con = mysql_connect("localhost","data","data");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}else {
mysql_select_db("database1", $con);
$result = mysql_query("SELECT * FROM Box1 ORDER BY id DESC LIMIT 1");
while($row = mysql_fetch_array($result))
{
echo $row['image'];
// NEXT STEP IS TO DISPLAY THE the IMAGE EXAMPLE: '<img src code<?php echo 'image'; ?>' >
}
}
mysql_close($con)
?>
if you could guide me to an exmaple of how to do this, that would be amazing, im so confused how one would implement HTML with PHP, thanks!!
<?php
... connect to DB ...
$sql = "SELECT imgurl FROM Box1 WHERE id=XXX";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($result);
?>
<img src="<?php echo $row['imgurl'] ?>" />
Also, it is helpful to become familiar with this operator for large chunks of html
echo <<<YOUR_TOKEN_NAME
<img src="$row['imgurl']" />
...misc html and php vars intermixed
YOUR_TOKEN_NAME;