Parse error on my php code.

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
mowgli
Forum Newbie
Posts: 6
Joined: Tue Nov 25, 2008 5:10 pm

Parse error on my php code.

Post by mowgli »

Hello

I am very new to php and recently have been trying to put a simple content management system on a website. However when i upload the the php file to the its coming back with:

"Parse error: syntax error, unexpected '=' in /home/sites/channel52.co.uk/public_html/admin.php on line 32"

I ve tried removing one of the = sign on line 32 however this does nt make a difference. I have tried reading into this but cant find the answer. Am i missing something form another line which is causing this problem such as a ; or a }

any help would be greatly appreciated.

Code: Select all

<?php
 
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.");
   }
   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 (($_POST['username'] == 'admin') && ($_POST['passwd'] == 'yourpassword')) {
        $_SESSION['username'] = 'login';
    }
   else {
       echo "<b>You login details is not correct. Pls 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 {
      // edit to link to your own static html files
      echo "<p align='center'>
       <a href="?file=../index.html">Home Page</a><br/>
       <a href="?file=../contact_us.html">Contact Us</a><br/>
       <br/>
       <em>Click on the links above to edit the files.</em><br/>
      <a href="?logout">logout</a></p>";
   }
}
?>
 
<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>&nbsp;</td>
      <td><input type="submit" name="Submit" value="Submit">&nbsp;&nbsp; <input type="reset" name="reset" value="Reset">
 </td>
    </tr>
  </table>
</form>
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Parse error on my php code.

Post by requinix »

Don't know what's on 32, but on 42 you have a glaring mistake.
Look at your post, especially the parts where it gets colorful. And then not so colorful. And then colorful again.
mmj
Forum Contributor
Posts: 118
Joined: Fri Oct 31, 2008 4:00 pm

Re: Parse error on my php code.

Post by mmj »

Adding to what tasairis said; its probably because you didn't use session_start.
mowgli
Forum Newbie
Posts: 6
Joined: Tue Nov 25, 2008 5:10 pm

Re: Parse error on my php code.

Post by mowgli »

Thanks for the reply, but i really dont see what you mean. I have a very basic knowledge and need to have it spelt out to me unfortunately.

I cant spot the glaring mistake, as obvious as it may seem.
What line do i need to place a session start? line 42 before the links? or somewhere else.

Thanks
mmj
Forum Contributor
Posts: 118
Joined: Fri Oct 31, 2008 4:00 pm

Re: Parse error on my php code.

Post by mmj »

You need to escape the quotes.
mowgli
Forum Newbie
Posts: 6
Joined: Tue Nov 25, 2008 5:10 pm

Re: Parse error on my php code.

Post by mowgli »

Which quotes? within the a href tag?
recon
Forum Newbie
Posts: 7
Joined: Thu Nov 27, 2008 10:31 am

Re: Parse error on my php code.

Post by recon »

Code: Select all

<a href="?file=../index.html">Home Page</a><br/>
should be

Code: Select all

<a href=[color=#FF0000]\[/color]"?file=../index.html[color=#FF0000]\[/color]">Home Page</a><br/>
notice the slashes before the quotes just before the URL.

Likewise on the line just below that, and again below that for the 'logout' section.

Anytime you use echo "stuff to echo", you need to escape any double quotations you use in the statement. Otherwise, the double quotations are interpreted by php to mean to end the echo statement, and if anything outside of the echo statement isn't a valid php command/syntax, an error will likely be returned.

(I myself am new to php, so correct me if I'm wrong on any of this, but I have found that this works for me).
mowgli
Forum Newbie
Posts: 6
Joined: Tue Nov 25, 2008 5:10 pm

Re: Parse error on my php code.

Post by mowgli »

It works!!!

Thank you so much :D
recon
Forum Newbie
Posts: 7
Joined: Thu Nov 27, 2008 10:31 am

Re: Parse error on my php code.

Post by recon »

Glad to hear.
Post Reply