I have a web page which is using php code to search and retrieve images matching tags the user enters. It is using mysql to store the image paths and retrieve the images for the user along with image information.
I'm trying to create a button within each retrieved image information to select it for download. This button will update the database table flag field. My problem is that I can't seem to call the function inside the fetch image/image info loop. I've tried one click methods and $_POST calls.
Thanks in advance
function fun(){
echo "Hello";
}
if(isset($_POST['insert'])){
$message= "The insert function is called.";
echo "The insert function is called.";
}
if(isset($_POST['select'])){
$message="The select function is called.";
}
$searchTags = $_POST['searchTag'];
$conn = new mysqli($servername,$username,$password,$db);
if ($conn->connect_error) {
die("Connection Error: ").$conn->connect_error;
}
$sql = "select pic_id, pic_name, pic_description, pic_tags FROM picture where pic_tags like'%$searchTags%'";
$result = $conn->query($sql);
if ($result->num_rows > 0 ){
while($row = $result->fetch_assoc()) {
$imgNumber = $row['pic_id'];
$imgSrc = $row['pic_name'];
$imgDescription =$row['pic_description'];
$imgTags = $row['pic_tags'];
echo "<div class='pictureBox'><br>Pic #".$imgNumber."
<br><input type='button' value='NEXT' onclick='document.write('<?php 'fun();'?>);
<br><input type='submit' name='insert' value='insert'>
<br>Pic Name: ".$imgSrc."
<br>Pic Description: ".$imgDescription."
<br> Pic Tags: ".$imgTags."
<br><a href='./galleryEditDB.php?picNumber=".$imgNumber."'>Edit</a>
<br><img src='".$imgSrc."'><br><br></div><br><br>";
echo $value;
}
} else {
echo "0 Results";
}
$conn->close();
onclick
is client side. You could send an AJAX request.pic_tags
cant use an index, might want to look into full text indexing.die("Connection Error: ").$conn->connect_error;
will not help youdie()
ends the script so you'd never get the error.