Hello!
I'm trying to make a small photoalbum, and it's going fairly well.
The picture-handling works as I want it, but I can't get the comment-handling to work. The following code displays the image just fine, and I can change the image by using javascript to update the .src of the image, but I can't get the same thing to work with innerHTML.
Below is index.php
<html>
<head>
<script type="text/javascript">
var i = 1;
var maxSize=<?php include 'maximg.php'; ?>;
var newWidth=100;
function onLoad(){
loadImg();
}
function loadImg(){
document.imgSrc.src = "image.php?id="+i;
document.getElementById('comment').innerHTML= "com_txt.php?id="+i;
}
function prev(){
i=i-1;
if (i<1){
i=1;
}
loadImg();
}
function next(){
i=i+1;
if (i>maxSize){
i=maxSize;
}
loadImg();
}
window.onload=onLoad;
</script>
</head>
<body>
<table border="1">
<tr>
<td>
<table border="1">
<tr>
<button type="button" onClick="prev();">Prev</button>
<button type="button" onClick="next();">Next</button>
</tr>
</table>
</td>
</tr>
</table>
<img name="imgSrc" id="imgSrc" onError="error();" alt="Picture not loaded"></img>
<hr>
<div id="comment"></div>
</body>
</html>
Below is image.php
<?php
include 'connect.php';
$id = $_GET['id'];
if(!isset($id) || empty($id)){
die("Please select your image!");
}else{
$query = mysql_query("SELECT * FROM tbl_images WHERE id='".$id."'");
$row = mysql_fetch_array($query);
$content = $row['image'];
$size = $row['size'];
$type = $row['type'];
$name = $row['name'];
header("Content-length: $size");
header("Content-type: $type");
header("Content-Disposition: attachment; filename=$name");
echo $content;
mysql_close();
}
?>
Below is com_text.php
<?php
include 'connect.php';
$id = $_GET['id'];
if(!isset($id) || empty($id)){
die("Please select your comment!");
}else{
$query = mysql_query("SELECT * FROM tbl_comments WHERE imageId=".$id);
mysql_close();
while($result = mysql_fetch_array($query)) {
echo " <b>Name</b> = " .$result["name"] . " <br>";
echo " <b>Text</b> = " .$result["text"] . " <br>";
echo " <b>Date</b> = " .$result["date"] . " <br>";
echo "<hr>";
}
}
?>
The attachment shows how it looks in the browser (even if the colors are distorted)
When I run index.php the image displays just fine, and I can change it with the next/prev buttons, but the text doesn't display properly at all!
If I run com_text.php?id=2 manually with the browser, I get the desired results
What am I doing wrong?
Why does the image change, when the text refuses to change?