Jump to content

Parse error: syntax error, unexpected '}'


cactus

Recommended Posts

Hey,

 

I know this is a really simple error but for the life of me I can't see where i'm going wrong. All the curly brackets all match up.

Can anybody help?

 

It's on line 47 which is marked.

<?php

print_r($_POST); // This will appear at the top of this page. It will contain every variable passed via a form that used the POST method.
if (isset($_REQUEST['logout'])) {
session_unset();
}

if (isset($_POST['submitUpdate'])) {
    if (get_magic_quotes_gpc()) {
	$_POST = array_map('stripslashes',$_POST);
}
	$fc = file_get_contents($_POST['file']);
	// truncate file
	$fw = fopen($_POST['file'], 'w+');
	$text = explode("<!-- EDITABLE -->",$fc);
	$newText = $text[0]."<!-- EDITABLE -->".htmlentities($_POST['content'])."<!--EDITABLE ->".$text[2];   
if (fwrite($fw, $newText)===FALSE) {
	die("Cannot write to file.")
}   //THIS IS LINE 47 
	fclose($fw);
exit("<div><span class='redText'>The file has been updated. Click <a href=\"index.php\">here</a> to go back to admin page.</div>");
}

if (isset($_POST['Submit'])) {
    if (isset($_POST['username']) && $_POST['username'] == '***' && $_POST['password'] == '***') {
	$_SESSION['username'] = 'login';
}
else {
	echo "<b>Your login details are not correct. Please login again</b>";
	}
}

if ($_SESSION['username']=='login') {
if (isset($_REQUEST['file'])) {
	$fc = file_get_contents($_REQUEST['file']);
	$text = explode("<!--EDITABLE-->",$fc);
echo "<form method='post' action=''><textarea name='content'>$text[1]</textarea>";
echo "<p><input type='hidden' name='file' value='".$_REQUEST['file']."' /><input name='submitUpdate' type='submit' value='Update Page'></form>";
}
}
else {
echo "<p align='center'>
	<a href='example1.html'>Example 1</a><br/>
	<a href='example2.html'>Example 2</a><br/>
	<br/>
	<em>Click on the links above to edit the files.</em><br/>
	<a href='index.php'>logout</a></p>";
}
session_destroy();
?>

<form method="post" action="">
<table width="400"  border="0" align="center" cellpadding="2" cellspacing="2">
<tr>
<td>Username: </td>
<td><input type="text" name="username"></td>
    </tr>
    <tr>
<td>Passwd: </td>
<td><input type="password" name="passwd"></td>
    </tr>
    <tr>
<td> </td>
<td><input type="submit" name="Submit" value="Submit">   <input type="reset" name="reset" value="Reset"> </td>
    </tr>
</table>
</form>

 

Thanks :)

Link to comment
Share on other sites

Lifesaver :)

 

However I have another problem which hopefully someone can help with.

I get the following error when I run the code on line 71.

 

Parse error: syntax error, unexpected '='

 

It's the same code as before but i've just pasted the section again. I am trying to create an editable region on m website. Can anyone help because with the = I get the error but without it it won't let me edit the pages it shows me the page.

else {
echo "<p align='center'>
	<a href="?file=../example1.html">Example1</a><br/> //THIS IS LINE 71
	<a href="?file=../example2.html">Example2</a><br/>
	<br/>
	<em>Click on the links above to edit the files.</em><br/>
	<a href='?index.php'>logout</a></p>";
}

Can someone please help I am completely confused as to why it won't let me do it either way. I need some expertise please :)

Link to comment
Share on other sites

Lifesaver :)

 

However I have another problem which hopefully someone can help with.

I get the following error when I run the code on line 71.

 

Parse error: syntax error, unexpected '='

 

It's the same code as before but i've just pasted the section again. I am trying to create an editable region on m website. Can anyone help because with the = I get the error but without it it won't let me edit the pages it shows me the page.

else {
echo "<p align='center'>
	<a href="?file=../example1.html">Example1</a><br/> //THIS IS LINE 71
	<a href="?file=../example2.html">Example2</a><br/>
	<br/>
	<em>Click on the links above to edit the files.</em><br/>
	<a href='?index.php'>logout</a></p>";
}

Can someone please help I am completely confused as to why it won't let me do it either way. I need some expertise please :)

 

You are breaking the echo at <a href="?. Try the following:

 

else {
echo "<p align='center'>
	<a href='?file=../example1.html'>Example1</a><br/>
	<a href='?file=../example2.html'>Example2</a><br/>
	<br/>
	<em>Click on the links above to edit the files.</em><br/>
	<a href='?index.php'>logout</a></p>";
}

Link to comment
Share on other sites

Well that solved that error thank you however I have another problem sorry.

 

When I click on example1 or example2 from the list its supposed to take me to that page but it just stays on the same page (the page with the list of editable pages).

 

Any ideas? Thanks :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.