[SOLVED]Spot the parse error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
m0nk3yb0y
Forum Newbie
Posts: 14
Joined: Mon Feb 20, 2006 11:07 pm

[SOLVED]Spot the parse error

Post by m0nk3yb0y »

Can anyone spot the parse error in the following code.

The error that is being outputted is this:
"Parse error: parse error in /var/www/vhosts/slick46.com/httpdocs/admin/cdman.php on line 262"

Code: Select all

<?php
include 'include/checkauth.php';
include 'include/header.php';
?>
<!-- content begins-->
<script type='text/javascript'>
<!--
/*This Function places bbcode tags around selected text in a textarea*/
function ubbc(open, end){
    var tArea = document.fa.text;
    var isIE = (document.all)? true : false;
    var open = (open)? open : "";
    var end = (end)? end : "";

    if(isIE){
        tArea.focus();
        var curSelect = document.selection.createRange();
        if(arguments[2]){
            curSelect.text = open + arguments[2] + "]" + curSelect.text + end;
        } else {
            curSelect.text = open + curSelect.text + end;
        }
    } else if(!isIE && typeof tArea.selectionStart != "undefined"){
        var selStart = tArea.value.substr(0, tArea.selectionStart);
        var selEnd = tArea.value.substr(tArea.selectionEnd, tArea.value.length);
        var curSelection = tArea.value.replace(selStart, '').replace(selEnd, '');
        if(arguments[2]){
            tArea.value = selStart + open + arguments[2] + "]" + curSelection + end + selEnd;
        } else {
            tArea.value = selStart + open + curSelection + end + selEnd;
        }
    } else {
        tArea.value += (arguments[2])? open + arguments[2] + "]" + end : open + end;
    }
}

// Helpline messages
b_help = "Bold Selected text: [b]text[/b]";
i_help = "Italic Selected text: [i]text[/i]";
u_help = "Underline Selected text: [u]text[/u]";
hr_help = "Insert horizontal line: [hr]";
p_help = "Insert image: [img]http://image_link[/img]";
w_help = "Insert URL: [url]http://somelink.com[/url] or [url=http://somelink.com]URL text[/url]";
e_help = "Insert email link: [email]me@email.com[/email]";
a_help = "Close all open bbCode tags";
s_help = "Font color: [color=red]text[/color]  Tip: you can also use color=#FF0000";
f_help = "Font size: [size=x-small]small text[/size]";
default_help = "Tip: Styles can be applied quickly to selected text.";

// Shows the help messages in the helpline window
function helpline(help) {
	document.fa.helpbox.value = eval(help + "_help");
}
//-->

</script>

<?PHP
//delete a cd
if($_REQUEST['task'] == 'del')
{
	$item = $db->get_row("SELECT * FROM cdMan WHERE idcdMan = '$_REQUEST[id]'");
	$tmb = $item->tmbname;
	$img = '../images/'.$item->imagename; 
	unlink($tmb);
	unlink($img);
	$db->query("DELETE FROM cdMan WHERE idcdMan = '$_REQUEST[id]'");
	echo"<META HTTP-EQUIV=Refresh CONTENT=\"1; URL=cdman.php\">";
	echo"<h2>CD Item Deleted!</h2>";
	exit;
}

//Edit cd details
if ($_REQUEST['task'] == 'ed')
{
$item = $db->get_row("SELECT * FROM cdMan WHERE idcdMan = '$_REQUEST[id]'");
echo "<h2>Edit CD Item</h2>
<form enctype=\"multipart/form-data\" name=\"fa\" action=\"cdman.php\" method=\"post\">
<input type=\"hidden\" name=\"id\" value=\"$item->idcdMan\">
<input type=\"hidden\" name=\"task\" value=\"update\">
<table>
<tr><td><p>Title</p></td><td><input type=\"text\" name=\"title\" value=\"$item->title\"size=40></td></tr>
<tr><td>&nbsp;</td><td>
					<a href=\"javascript:ubbc('[b]','[/b]')\" onMouseOver=\"helpline('b')\" onMouseOut=\"helpline('default')\"><img src='images/e_bold2.gif'  border=0></a> 
    				<a href=\"javascript:ubbc('[i]', '[/i]')\" onMouseOver=\"helpline('i')\" onMouseOut=\"helpline('default')\"><img src='images/e_italic2.gif'  border=0></a>
					<a href=\"javascript:ubbc('[u]', '[/u]')\" onMouseOver=\"helpline('u')\" onMouseOut=\"helpline('default')\"><img src='images/e_uline2.gif'  border=0></a>
    				<a href=\"javascript:ubbc('[hr]')\" onMouseOver=\"helpline('hr')\" onMouseOut=\"helpline('default')\"><img src='images/e_hr.gif'  border=0></a>
    				<a href=\"javascript:ubbc('[url]', '[/url]')\" onMouseOver=\"helpline('w')\" onMouseOut=\"helpline('default')\"><img src='images/createlink.gif'  border=0></a>
					<a href=\"javascript:ubbc('[email]', '[/email]')\" onMouseOver=\"helpline('e')\" onMouseOut=\"helpline('default')\"><img src='images/email.gif'  border=0></a></td></tr>
<tr><td>&nbsp;</td><td><input type=\"text\" name=\"helpbox\" size=\"50\" maxlength=\"100\" style=\"width:500px; font-size:10px; color:#FFF\" class=\"helpline\" value=\"Tip: Styles can be applied quickly to selected text.\" /></td></tr>
<tr><td valign=top><p>Text</p> </td><td> <textarea name=\"text\" rows=10 cols=60>$item->text</textarea></td></tr>
<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"250000\" />
<tr><td><p>Cd Cover Pic</p></td><td><input type=\"file\" name=\"imagefile\"></td></tr>
<tr><th colspan=2 align=\"right\"><p><input type=\"submit\" name=\"update\" value=\"update\"></p></th></tr>
</form>
</table>";
exit;
}
//add a cd
if($_REQUEST['task'] == 'add' OR $_REQUEST['task'] == 'update')
{
//If the Submitbutton was pressed do:
//instaniate Form Validator Object
$fv = new FormValidator();

//Print Error Msgs to browser
$fv->isEmpty("title", "Please enter a Title for your cd");
$fv->isEmpty("text", "Please enter a description of the cd or a track listing");

	//Perform Validation
	if ($fv->isError())
	{
	$errors = $fv->getErrorList();
	echo "<h3>The operation could not be performed because one ormore error(s) occurred.</h3> 
			<p>Please resubmit the form after making the following changes:";
	echo "<ul>";
		foreach ($errors as $e)
		{ 
		echo "<li>" .$e['msg'];
		}
	echo "</ul>";
	echo "<p>Please <a href=\"javascript:history.back()\">GO BACK</a> and fill out ALL the required fields</p>";
	exit;
	}
	else	
	{
	//Below We start the image upload
	//Check image file size
	if ($_FILES[imagefile][size] >250000)
		{
		$msg=$msg."<h3>Your uploaded file size is more than 250KB so please reduce the file size and then upload. Visit the help page to know how to reduce the file size.<BR>";
		$file_upload="false";
		}
	//Check image file extension
	if (!($_FILES[imagefile][type] == "image/pjpeg" OR $_FILES[imagefile][type] == "image/gif" OR $_FILES[imagefile][type] == "image/jpeg"))
		{
		$msg=$msg."<h3>Your uploaded file must be a JPG or GIF. Other file types are not allowed<BR>";
		$file_upload="false";
		}
	if($file_upload == 'false')
		{
		echo $msg;
		echo "<p>".print_r($_FILES);
		exit;
		}
		else
		{
		$imagefile_name = $_FILES[imagefile][name];
		//All good proceed with the upload
		$add="../images/imagefile_name";		//Path where large image will be stored
		$tsrc="../images/tmbs/imagefile_name"; // Path where thumb nail image will be stored
		
		if(move_uploaded_file ($_FILES[imagefile][tmp_name], $add))
			{
			echo "<h3>Image Successfully Added!</h3>";
			exit;
			}
			else
			{
			echo "<h3>Failed to upload file Contact support@webberoo.com.au to fix the problem</h3>";
			echo "<p>".print_r($_FILES);
			exit;
			}

			///////// Start the thumbnail generation//////////////
			$n_width=100; // Fix the width of the thumb nail images
			$n_height=100; // Fix the height of the thumb nail imaage
			/////////////////////////////////////////////// Starting of GIF thumb nail creation///////////
			if (@$_FILES[imagefile][type]=="image/gif")
				{
				$im=ImageCreateFromGIF($add);
				$width=ImageSx($im);              // Original picture width is stored
				$height=ImageSy($im);            // Original picture height is stored
				$newimage=imagecreatetruecolor($n_width,$n_height);
				imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
				imagegif($newimage,$tsrc);
				chmod("$tsrc",0777);
				}
				////////////// starting of JPG thumb nail creation//////////
				if(@$_FILES[imagefile][type]=="image/pjpeg" OR @$_FILES[imagefile][type]=="image/jpeg")
				{
				$im=ImageCreateFromJPEG($add);
				$width=ImageSx($im); // Original picture width is stored
				$height=ImageSy($im); // Original picture height is stored
				$newimage=imagecreatetruecolor($n_width,$n_height);
				imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
				ImageJpeg($newimage,$tsrc);
				chmod("$tsrc",0777);
				}
			//////////////// End of JPG thumb nail creation //////////
			//Now add to database
			if (@$_REQUEST['task'] == 'add')
				{
				$db->query("INSERT INTO cdMan (title,text,imagename,tmbname) VALUES ('$_POST[title]', '$_POST[text]', '$_FILES[imagefile][name]','$_FILES[imagefile][name]')");
				//Print success to user
				//echo "<META HTTP-EQUIV=Refresh CONTENT=\"1; URL=cdman.php\">";
				echo "<h3>$_POST[title] Successfully Added!</h3>";
				exit;
				}
				else
				{
				echo "<h3>Error Contact support@webberoo.com.au to fix the problem</h3>";
				echo "<p>DEBUG INFO:".print_r($_FILES);
				exit;
				}
			if (@$_REQUEST['task'] == 'update')
				{
				$db->query("UPDATE cdMan SET title='$_POST[title]', text='$_POST[text]', imagename='$imagefile_name', tmbname='$imagefile_name' WHERE idcdMan = '$_REQUEST[id]'");
				//Print success to user
				//echo "<META HTTP-EQUIV=Refresh CONTENT=\"1; URL=cdman.php\">";
				echo "<h3>$_POST[title] Successfully Updated!</h3>";
				exit;
				}
				else
				{
				echo "<h3>Error Contact support@webberoo.com.au to fix the problem</h3>";
				echo "<p>DEBUG INFO:".print_r($_FILES);
				exit;
				}
	}
} 
?>
<h2>Add a CD</h2>
<form enctype="multipart/form-data" name="fa" action="cdman.php" method="post">
<input type="hidden" name="task" value="add">
<table>
<tr><td><p>CD Title</p></td><td><input type="text" name="title" size=40></td></tr>
<tr><td>&nbsp;</td><td>
					<a href="javascript:ubbc('[b]','[/b]')" onMouseOver="helpline('b')" onMouseOut="helpline('default')"><img src='images/e_bold2.gif'  border=0></a> 
    				<a href="javascript:ubbc('[i]', '[/i]')" onMouseOver="helpline('i')" onMouseOut="helpline('default')"><img src='images/e_italic2.gif'  border=0></a>
					<a href="javascript:ubbc('[u]', '[/u]')" onMouseOver="helpline('u')" onMouseOut="helpline('default')"><img src='images/e_uline2.gif'  border=0></a>
    				<a href="javascript:ubbc('[hr]')" onMouseOver="helpline('hr')" onMouseOut="helpline('default')"><img src='images/e_hr.gif'  border=0></a>
    				<a href="javascript:ubbc('[url]', '[/url]')" onMouseOver="helpline('w')" onMouseOut="helpline('default')"><img src='images/createlink.gif'  border=0></a>
					<a href="javascript:ubbc('[email]', '[/email]')" onMouseOver="helpline('e')" onMouseOut="helpline('default')"><img src='images/email.gif'  border=0></a></td></tr>
<tr><td>&nbsp;</td><td><input type="text" name="helpbox" size="50" maxlength="100" style="width:500px; font-size:10px; color:#FFF" class="helpline" value="Tip: Styles can be applied quickly to selected text." /></td></tr>
<tr><td valign=top><p>Description</p> </td><td> <textarea name="text" rows=10 cols=60></textarea></td></tr>
<input type="hidden" name="MAX_FILE_SIZE" value="250000" />
<tr><td><p>Cd Cover Pic</p></td><td><input type="file" name="imagefile"></td></tr>
<tr><th colspan=2 align="right"><input type="submit" name="submit" value="Add"></th></tr>
</table>
</form>
<hr>
<h2>CD's in the database</h2>
<table>
<?PHP
if ($item = $db->get_results("SELECT * FROM cdMan ORDER BY idcdMan DESC"))
{
	foreach ($item as $items)
	{
	echo"<tr><td><a href='../images/$items->imagename' target='_blank'><img src='../images/tmbs/$items->tmbname'></a></td><td><p>$items->title</p></td><td><a href=\"cdman.php?id=$items->idcdMan&task=ed\">EDIT</a></td><td><a href=\"cdman.php?id=$items->idcdMan&task=del\">DELETE</a></td>\n</tr></tr>";
	}
}
else
{
	echo"<tr><td><p>I'm Sorry There Are No CD's In The Database</td></tr>";
}
?>
</table>
<!--Contant ends-->
<?PHP
include 'include/footer.php';
?>
Last edited by m0nk3yb0y on Tue Apr 11, 2006 5:27 am, edited 1 time in total.
wyred
Forum Commoner
Posts: 86
Joined: Mon Dec 20, 2004 1:59 am
Location: Singapore

Post by wyred »

Line 251, some of your href's are using double quotes instead of single.
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

Starting with the echo statement on line 78, you have lots of unescaped double quotes.
The same on line 69.
m0nk3yb0y
Forum Newbie
Posts: 14
Joined: Mon Feb 20, 2006 11:07 pm

Post by m0nk3yb0y »


PostPosted: Tue Apr 11, 2006 5:10 am Post subject:
Line 251, some of your href's are using double quotes instead of single.
Replced double quotes with single and still getting same error. Thanx for pointing that out though.
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

And on line 123.
And on line 251.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

this line:

echo "<h2>Edit CD Item</h2>

has no closing tag and code after it has no \" so im assuming your wanting to break out of PHP which you havent done
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

And, finally, on line 102, you have an un-matched content identifier '{' after your if statement.
You need to close this if statement somewhere on your page.
m0nk3yb0y
Forum Newbie
Posts: 14
Joined: Mon Feb 20, 2006 11:07 pm

Post by m0nk3yb0y »

Starting with the echo statement on line 78, you have lots of unescaped double quotes.
The same on line 69.
This is wierd in the script on my pc the double quotes in those echos statements are escaped but when I posted the code in between the php tags it seemed to ignore the \"s
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

Ah yes, it does that - most annoying.

In that case, you only need to add the closing brace } to line 102 - it goes somewhere around 220, I assume?
m0nk3yb0y
Forum Newbie
Posts: 14
Joined: Mon Feb 20, 2006 11:07 pm

Post by m0nk3yb0y »

And, finally, on line 102, you have an un-matched content identifier '{' after your if statement.
You need to close this if statement somewhere on your page.
That fixed it thanx sooo much I was begining to pull out my hair :?
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

If the script fails at the very last line, then it's normally a missing } from somewhere :)
Please edit your first post to add '[Solved]' to your subject line.
Post Reply