Page 1 of 1

Annoying typo (I think)

Posted: Wed Jun 21, 2006 9:27 am
by webchimp
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I'm quite new tp PHP and I've been working through a book and doing the examples/exercises in it. Occasionally I run up a script that won't work for some reason, normally a typo on my part, but occasionally a typo on their part and I can normally figure out whats wrong with it. 
With the following though I just can't see what the problem is. I've tried the book listing and it works fine. Mine should be identicle except for layout and variable naming conventions. It's probably just a [i]little[/i] tiny error but I just can't find it. Any help would be much appreciated.
It's a script that asks the user for some inputs and draws an image on screen. Basically a coloured box with some text coloured/sized etc by the user.
The error I'm geting is:

[quote]Parse error: parse error, unexpected T_VARIABLE, expecting ',' or ';' in /home/webchimp/public_html/php_learn/imageCreateUser.php on line 72[/quote]

The Origional code is:

Code: Select all

<?
if ($_POST[op] != "do") {
	//show form
	echo "<HTML>
	<HEAD>
	<TITLE>Image Creation Form</TITLE>
	</HEAD>
	<BODY>
	<H1>Create an Image</H1>
	<FORM method=\"POST\" action=\"$_SERVER[PHP_SELF]\">
	<P><strong>Image Size:</strong><br>
	W: <input type=\"text\" name=\"w\" size=5 maxlength=5> H: <input type=\"text\" name=\"h\" size=5 maxlength=5>
	<P><strong>Background Color:</strong><br>
	R: <input type=\"text\" name=\"b_r\" size=3 maxlength=3> G: <input type=\"text\" name=\"b_g\" size=3 maxlength=3>
 	B: <input type=\"text\" name=\"b_b\" size=3 maxlength=3>
	<P><strong>Text Color:</strong><br>
	R: <input type=\"text\" name=\"t_r\" size=3 maxlength=3> G: <input type=\"text\" name=\"t_g\" size=3 maxlength=3>
 	B: <input type=\"text\" name=\"t_b\" size=3 maxlength=3>
	<P><strong>Text String:</strong><br>
	<input type=\"text\" name=\"string\" size=35>
	<P><strong>Font Size:</strong><br>
	<select name=\"font_size\">
	<option value=1>1</option>
	<option value=2>2</option>
	<option value=3>3</option>
	<option value=4>4</option>
	<option value=5>5</option>
	</select>
	<P><strong>Text Starting Position:</strong><br>
	X: <input type=\"text\" name=\"x\" size=3 maxlength=3> Y: <input type=\"text\" name=\"y\" size=3 maxlength=3>
	<input type=\"hidden\" name=\"op\" value=\"do\">
	<P><input type=\"submit\" name=\"submit\" value=\"create image\">
	</FORM>
	</BODY>
	</HTML>";

} else {
	//create image
	//create the canvas
	$myImage = ImageCreate($_POST[w], $_POST[h]);

	//set up some colors
	$background = ImageColorAllocate ($myImage, $_POST[b_r], $_POST[b_g], $_POST[b_b]);
	$text = ImageColorAllocate ($myImage, $_POST[t_r], $_POST[t_g], $_POST[t_b]);

	// write the string at the top left
	ImageString($myImage, "$_POST[font_size]", "$_POST[x]", "$_POST[y]", "$_POST[string]", $text);

	//output the image to the browser
	header ("Content-type: image/png");
	ImagePNG($myImage);

	//clean up after yourself
	ImageDestroy($myImage);
}
?>
And my version is:

Code: Select all

/******************************************************************************
* Filename: imageCreateUser.php                                               *
* Created 20th of June 2006                                                   *
*                                                                             *
* Based on listing 14.7 p 282 SAMS PHP, MySQL & Apache all in one.            *
*                                                                             *
* Script that accepts several user inputs to create a graphic with text.      *
* User defines background/text colour, font size and start position.          *
******************************************************************************/
<?php
	if($_POST[op] != "do")
	{
		//Show form
		echo "<html>
			<head>
				<title>Image Creation Form</title>
			</head>
			<body>
				<h1>Create an image</h1>
				<form method = \"POST\" action = \"$_SERVER[PHP_SELF]\">
					<p>
						<Strong>Image size:</strong><br />
						W: <input type = \"text\" name = \"width\" size = 5 maxLength = 5>
						H: <input type = \"text\" name = \"height\" size = 5 maxLength = 5>
					</p>
					<p>
						<Strong>Background Colour:</strong><br />
						R: <input type = \"text\" name = \"bgRed\" size = 5 maxLength = 5>
						G: <input type = \"text\" name = \"bgGreen\" size = 5 maxLength = 5>
						B: <input type = \"text\" name = \"bgBlue\" size = 5 maxLength = 5>
					</p>
					<p>
						<Strong>Background Text:</strong><br />
						R: <input type = \"text\" name = \"tRed\" size = 5 maxLength = 5>
						G: <input type = \"text\" name = \"tGreen\" size = 5 maxLength = 5>
						B: <input type = \"text\" name = \"tBlue\" size = 5 maxLength = 5>
					</p>
					<p>
						<Strong>Text String:</strong><br />
						<input type = \"text\" name = \"string\" size = 35>
					</p>
					<p>
						<Strong>Font size:</strong><br />
						<select name = \"fontSize\">
							<option value = 1>1</option>
							<option value = 2>2</option>
							<option value = 3>3</option>
							<option value = 4>4</option>
							<option value = 5>5</option>
						</select>
					</p>
					<p>
						<Strong>Text Starting Position:</strong><br />
						X: <input type = \"text\" name = \"xPos\" size = 3 maxLength = 3>
						Y: <input type = \"text\" name = \"yPos\" size = 3 maxLength = 3>
					</p>
				</form>
			</body>
		</html>
	}
	else
	{
		//Create image
		//Create the canvas
		$myImage = ImageCreate($_POST[width], $_POST[height]);
		
		//Set up some colours
		$background = ImageColorAllocate($myImage, $_POST[bgRed], $_POST[bgGreen], $_POST[bgBlue]);
		$text = ImageColorAllocate($myImage, $_POST[tRed], $_POST[tGreen], $_POST[tBlue]);
		
		//Write the string at the top left
/*Line 72*/ImageString($myImage, "$_POST[fontSize]", "$_POST[xPos]", "$_POST[yPos]", "$_POST[string]", $text);/*<<<<Line 72*/
		
		//Output image to browser
		header ("Content-type: image/png");
		ImagePng($myImage);
	
		//Clean up
		ImageDestroy($myImage);
	}
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Wed Jun 21, 2006 9:43 am
by Weirdan
looks like you forgot the closing quote after the </html> (It would be obvious to you if you had used syntax highlighting).

Posted: Wed Jun 21, 2006 10:33 am
by webchimp
Nope, it's there just before the 'else' statement
</body>
</html>
}
else
{
//Create image

Posted: Wed Jun 21, 2006 10:39 am
by GM
No it's not:

Needs to be </html>"

Posted: Wed Jun 21, 2006 10:54 am
by webchimp
yep, just spotted that. had to be </html>";

Oh my dreaded enemy the semi-colon! How I hate thee :)

Cheers for the help