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!
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.
I have created a Wordpress page to show dynamic content based on MySQL database. The content will be shown based on the URL parameter.
Ex: https://domainname.com/hotel-details/?hotelcode=First-Hotel
Is it possible to generate a new post for each database row?
So, instead of using an URL parameter like one above, the URL could be: https://domainname.com/hotel-details/First-Hotel
I created this dynamic page by inserting a PHP code to a Wordpress page (I use Advanced Ads plugin to insert the code)
<?php
if (isset($_GET['hotelcode']))
{
$hotelcode = $_GET['hotelcode'];
}
else
{
$hotelcode = "";
}
include 'dbconnect.php'; // MySQL DB connection
$dbconnect = mysqli_connect($host, $user, $password, $database);
$dbresult = mysqli_query($dbconnect, "
SELECT *
FROM HotelDatabase
WHERE HotelSlug='$hotelcode'
");
foreach ($dbresult as $row);
$HotelName= $row['HotelName']; $HotelDetail= $row['HotelDetail'];
$Image= $row['Image']; $Review= $row['Review'];
?>
<?php if($dbresult->num_rows == 0)
{
echo "<h1 style='text-align: center;'>No Data Found</h1>
}
else
{
echo "
<br><br>
<h1 style='text-align: center; color: blue;'>$Hotel Name</h1>
<img src='$Image'><br>
$HotelDetail<br>
$Review
";
}
?>
I have no problem to display the content on the page, what I want is, show the content on the new generated pages for each database row instead of using a unique URL parameter.
Change
https://domainname.com/hotel-details/?hotelcode=First-Hotel
to
https://domainname.com/hotel-details/First-Hotel
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"]."; ?>">
I am creating a website that stores information of homes like address, city etc. I got the upload to database part done and I got the search the database and display the information done.
But now my plan with that is you get the search results and from there your suppose to get the option to view the full profile of that home via link. Displaying the full profile with the information gathered from the database is already done through a separate php file. Now when I link the php file it will only display the last column in the database. How can I link it so when I click on "view full profile" it will connect to the correct data/profile that corresponds to the different address or price. Or if i cant use an html link what can I use? Is that impossible?
here is the code that displays the search results I have successfully been able to search the database and display it
<?php
if($sql->num_rows){
while ($row = $sql->fetch_array(MYSQLI_ASSOC)){
echo '<div id="listing">
<div id="propertyImage">
<img src="images/'.$row['imageName1'].'" width="200" height="150" alt=""/>
</div>
<div id="basicInfo">
<h2>$'.$row['Price'].'</h2>
<p style="font-size: 18px;"># '.$row['StreetAddress'].', '.$row['City'].', BC</p>
<p>'.$row['NumBed'].' Bedrooms | '.$row['NumBath'].' Bathrooms | '.$row['Property'].'</p>
<br>
<p>View Full Details | Get Directions
</div>
</div>';
height="150" alt=""/>';
}
}
else
{
echo '<h2>0 Search Results</h2>';
}
?>
Here is the php to display the information outputtest.php
<?php
mysql_connect("localhost","root","31588patrick");
#mysql_select_db("test") or die( "Unable to select database");
$query="SELECT * FROM propertyinfo";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$i=0;
while ($i < $num) {
$varStreetAddress=mysql_result($result,$i,"StreetAddress");
$varCity=mysql_result($result,$i,"City");
$varProperty=mysql_result($result,$i,"Property");
$varNumBed=mysql_result($result,$i,"NumBed");
$varNumBath=mysql_result($result,$i,"NumBath");
$varPrice=mysql_result($result,$i,"Price");
$varEmail=mysql_result($result,$i,"Email");
$varPhone=mysql_result($result,$i,"Phone");
$varUtilities=mysql_result($result,$i,"utilities");
$varTermLease=mysql_result($result,$i,"TermLease");
$varNotes=mysql_result($result,$i,"Notes");
$image1=mysql_result($result,$i,"imageName1");
$image2=mysql_result($result,$i,"imageName2");
$image3=mysql_result($result,$i,"imageName3");
$image4=mysql_result($result,$i,"imageName4");
$i++;
}
?> html code will go after this
Thanks
edit its working
<?php
////////////using mysqli to connect with database
$mysqli = new mysqli("localhost","root","31588patrick", "test");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
///////////set variables
$record_id = $_GET['record_id'];
$sql = $mysqli->query("select * from propertyinfo where StreetAddress like '%$record_id%'");
if($sql === FALSE) {
die(mysql_error()); // TODO: better error handling
}
if($sql->num_rows){
while ($row = $sql->fetch_array(MYSQLI_ASSOC)){
$varStreetAddress=$row['StreetAddress'];
$varCity=$row['City'];
$varProperty=$row['Property'];
$varNumBed=$row['NumBed'];
$varNumBath=$row['NumBath'];
$varPrice=$row['Price'];
$varEmail=$row['Email'];
$varPhone=$row['Phone'];
$varUtilities=$row['utilities'];
$varTermLease=$row['TermLease'];
$varNotes=$row['Notes'];
$image1=$row['imageName1'];
$image2=$row['imageName2'];
$image3=$row['imageName3'];
$image4=$row['imageName4'];
}
}
If the link you are using is only fetching the last record in the database table, then the underlying query that is used must be fetching the last record instead of the intended record. Am I correct in understanding the problem you are having? That any link you use is just returning the last record in the database?
Posting a code snippet will help the community take a closer look.
in your php file, you run a query for all records, but ...
$record_id = mysql_real_escape_string($_GET["record_id"]);
$query="SELECT * FROM propertyinfo WHERE id=$record_id";
your link needs to attach a parameter that will allow you to query for a specific record.
a href="outputtest.php&record_id=8"
AND you would also want to check what is in the GET parameter before sticking it into the query! I know mysql_real_escape_string is outdated.
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>
";
}