Page 1 of 1

Parse error on my php code.

Posted: Tue Nov 25, 2008 5:40 pm
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>

Re: Parse error on my php code.

Posted: Tue Nov 25, 2008 7:30 pm
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.

Re: Parse error on my php code.

Posted: Wed Nov 26, 2008 7:27 am
by mmj
Adding to what tasairis said; its probably because you didn't use session_start.

Re: Parse error on my php code.

Posted: Wed Nov 26, 2008 2:37 pm
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

Re: Parse error on my php code.

Posted: Wed Nov 26, 2008 2:44 pm
by mmj
You need to escape the quotes.

Re: Parse error on my php code.

Posted: Thu Nov 27, 2008 10:04 am
by mowgli
Which quotes? within the a href tag?

Re: Parse error on my php code.

Posted: Thu Nov 27, 2008 10:47 am
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).

Re: Parse error on my php code.

Posted: Thu Nov 27, 2008 12:01 pm
by mowgli
It works!!!

Thank you so much :D

Re: Parse error on my php code.

Posted: Thu Nov 27, 2008 9:57 pm
by recon
Glad to hear.