PHP ~ updating image

Status
Not open for further replies.

Xrproto

Waste of e-space
Aug 1, 2006
1,871
13
0
Okay so I've been hard at work...kind of.

Anyway I've made a script to screen scrap some data and put it to my data base. Then I take the data and out put it to an image file. I've even went further and made it so where a "user" could modify fonts, colors, what not of the image.

Now everything works good EXCEPT after the user has updated the image once it's returned to the page updated BUT when they try to update again the image on the page won't refresh BUT it still updates the values in my database.

So I'm thinking this is a post data issue in the form but I can't think of a fix to refresh that image every time without doing a complete page refresh.
 


This is the code that fires when they update (submit)

it will return the updated image but if they input data into the form again and hit update it won't refresh the image unless you refresh the whole page again.
EDIT: the PHP markup looks like shit on here :p
PHP:
// Add GPID to database
if(isset($_POST['add']))
{
include './system/config.php';
include './system/opendb.php';

$gpid = $_POST['gpid'];
$fontsize = $_POST['fontsize'];

$query = mysql_query("SELECT gpid FROM mp WHERE gpid = '" . $gpid . "'");
if($query && mysql_num_rows($query) > 0)
{
		$img = "img src=http://www.mysite.com/system/stats/$gpid.png";
		$img2 = "[img]http://www.mysite.com/system/stats/$gpid.png[/img]";
		$sty = "border:1px solid black;";
		
		mysql_query("UPDATE mp SET fontsize = '$fontsize' WHERE gpid = '" . $gpid . "'");		
		
		$quer = mysql_query("SELECT tag FROM mp WHERE gpid = '" . $gpid . "'");
		
		if(mysql_num_rows($quer) > 0){
          while($row=mysql_fetch_array($quer)){
   			$tag= $row['tag'];
		} }else{echo "ERROR";}

		include 'imgtest.php';
		
		echo "<img src=http://www.mysite.com/system/stats/$gpid.png><br><br><br>";
		echo "<input style='$sty' onFocus=this.select() size=60 type=text value=http://www.mysite.com/system/stats/$gpid.png><br>";
		echo "<input style='$sty' onFocus=this.select() size=60 type=text value='<$img>'><br>";
		echo "<input style='$sty' onFocus=this.select() size=60 type=text value='$img2'><br>";
		
		include './system/closedb.php';
}

else
{
		mysql_query("INSERT INTO mp (gpid, fontsize) VALUES ('$gpid','$fontsize')") or die('Error, insert query failed');
		
		$quer = mysql_query("SELECT tag FROM mp WHERE gpid = '" . $gpid . "'");
		
		if(mysql_num_rows($quer) > 0){
          while($row=mysql_fetch_array($quer)){
   			$tag = $row['tag'];
		} }else{echo "ERROR";}

		include 'imgtest.php';
		
		$img = "img src=http://www.mysite.com/system/stats/$gpid.png";
		$img2 = "[img]http://www.mysite.com/system/stats/$gpid.png[/img]";
		$sty = "border:1px solid black;";
		echo "New GPID added<br><br>";
		echo "<img src=http://www.mysite.com/system/stats/$gpid.png><br><br><br>";
		echo "<input style='$sty' onFocus=this.select() size=60 type=text value=http://www.mysite.com/system/stats/$gpid.png><br>";
		echo "<input style='$sty' onFocus=this.select() size=60 type=text value='<$img>'><br>";
		echo "<input style='$sty' onFocus=this.select() size=60 type=text value='$img2'><br>";
}
}
 
...
Now everything works good EXCEPT after the user has updated the image once it's returned to the page updated BUT when they try to update again the image on the page won't refresh BUT it still updates the values in my database.

Sounds like it could be a cached image. Add some PHP headers:
PHP:
 <?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
?>
I hope I understood you correctly. If not, PM me if you'd like.
 
That's what it was. A caching issue in IE. I was having the problem at work were I can only use IE and I get home, worked fine in Firefox so I threw two lines in the htaccess and viola!

Thanks esnagel!
 
Be careful, having this always expired will mean large bandwidth issues. So ensure you only send the headers when the image has actually updated (to save bandwidth at least)
 
Status
Not open for further replies.