Tjk Posted June 10, 2006 Share Posted June 10, 2006 Code in main page...[code]<?$var= 1;?><form method="POST" action="map.php"><input type="image" src="imagecreate2.php?var='$var'" height="300" width= "300" /></form>[/code]Code in image create...[code] if(isset($_GET['var'])){ $var= $_GET['var']; } mysql_query("SELECT * from table WHERE id='$var'") or die(mysql_error());//does something to an image and outputs it using imagepng($img);[/code]The problem is that the image now doesn't load on the main page. Could anyone point out where I'm going wrong?Regards-Tjk Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted June 10, 2006 Share Posted June 10, 2006 Can you post the code that sends the image back to the browser. You are probably missing the header() fucntion that sets the correct output type.Ken Quote Link to comment Share on other sites More sharing options...
Tjk Posted June 10, 2006 Author Share Posted June 10, 2006 Sure. Here it is....[taken from imagecreate2.php][code]<? $im= imagecreatefrompng('maptemp.png'); if(isset($_GET['battle'])){ $battle= $_GET['battle']; } mysql_connect("localhost", "user", "password")or die(mysql_error()); mysql_select_db("database"); $query= mysql_query("SELECT * from battles WHERE battle='$battle'")or die(mysql_error()); while($row= mysql_fetch_array($query)){ $unit= $row['unit']; $unitx= $row['xcoord']; $unity= $row['ycoord']; $lcoordx= $unitx- 5; $lcoordy= $unity - 5; $rcoordx= $unitx + 5; $rcoordy= $unity + 5; $color= imagecolorallocate($im, 0xFF, 0xFF, 0xFF); imagefilledrectangle($im, $lcoordx, $lcoordy, $rcoordx, $rcoordy, $color); } imagepng($im);?>[/code] Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted June 10, 2006 Share Posted June 10, 2006 You're missing the "header()" function that tells the web browser to expect image data:Add the following line to your funtion[code]<?php header('Content-type: image/png'); ?>[/code] before the line [code]<?php imagepng($im); ?>[/code]Ken Quote Link to comment Share on other sites More sharing options...
Tjk Posted June 10, 2006 Author Share Posted June 10, 2006 I've added the header() function just above imagepng($im) and it doesn't work.Before I added the parameter into the query string for imagecreate2.php when I was just using a mysql statement with no WHERE condition everything was working fine and the map loaded. It was only when I added the parameter and to allow for the WHERE condition that it no longer works. Any ideas?Help appreciated as always. Quote Link to comment Share on other sites More sharing options...
.josh Posted June 10, 2006 Share Posted June 10, 2006 i don't see in your script where you are passing the battle variable to your imagecreate2.php script. it seems as though when you do this:if(isset($_GET['battle'])){ $battle= $_GET['battle']; }$_GET['battle'] is not set, and therefore $battle is never set, either, so when you do your query, it selects nothing.edit: did you mean to do $_GET['var'] ? Quote Link to comment Share on other sites More sharing options...
joquius Posted June 10, 2006 Share Posted June 10, 2006 if it's purely a query page do thisif (isset ($_GET['battle'])) $battle = $_GET['battle']; else die ("Missing Variables");or just incapsulate the entire code in the $_GET['battle'] if() function Quote Link to comment Share on other sites More sharing options...
Tjk Posted June 10, 2006 Author Share Posted June 10, 2006 @ Crayon Violent: Earlier in the script the variable $battle is defined. Sorry, the original code I posted was a test script I set up to test if it was something wrong with my code. Everything is identical except in my example I used $var instead of $battle. $battle is definately set within the main script and ready to pass via the query string into the image creation script.I'm using a script called 'map.php' and through the img src I'm calling the script imagecreate2.php to generate the image.@joquius: I need the variable $battle to be set at all times so an else isn't really an option. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted June 10, 2006 Share Posted June 10, 2006 I just took a closer look at the original code you posted:[code]<?php$var= 1;?><form method="POST" action="map.php"><input type="image" src="imagecreate2.php?var='$var'" height="300" width= "300" /></form>[/code]Notice that the "<input>" line is outside the PHP tags, so you are passing the literal string "[b]'$var'[/b]" to your script, not the value of [b][!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]$var[!--colorc--][/span][!--/colorc--][/b].What you really should have there is:[code]<input type="image" src="imagecreate2.php?var=<?php echo $var; ?>" height="300" width= "300" />[/code]If you look at the generated source before and after you've made this change, you should see the difference.Ken Quote Link to comment Share on other sites More sharing options...
.josh Posted June 11, 2006 Share Posted June 11, 2006 ooh good eye, [img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.