Jump to content

Re: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';'


Recommended Posts

Hey guys,

 

I am getting the same error and I can't figure out why, I've double checked all my brackets and everything. It's probably just something simple but once you've been staring at it for ages you can't see very much.

 

My code is:

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

 

I've highlighted the line that the error appears on , can anybody help me?  :)

Please don't hijack other threads, even if you're having the same problem.

 

Please post more of your code, sometimes the error can be in a line a few lines above where PHP notices the problem.

 

Ken

sorry I didn't realise, I thought because I had a similar problem I could post it there obviosuly not, noted!

 

Here is more of my code:

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 (isset($_POST['username'] == '***') && ($_POST['password'] == '***')) { //THIS LINE
$_SESSION['username'] = 'login';
    }
else {
echo "<b>Your login details are not correct. Please login again</b>";
    }
}

 

Can anyone help please? :)

Indentation is your friend. 

 

You have blocks that start and end for no apparent reason, so it's hard to sort out your code, but it looks like you have an unmatched end block curly bracket at the end.. 

 

 

Here is your code if it was indented in a reasonable manner:

 



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("",$fc);
$newText = $text[0]."".htmlentities($_POST['content'])."

My full code is:

<?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.");
}    
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['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='example.html'>Example</a><br/>
<a href='example2.html'>Example2</a><br/>
<br/>
<em>Click on the links above to edit the files.</em><br/>
<a href='staff.php'>logout</a></p>";
}
session_destroy();
?>

obviously without the indentation that you were kind enough to do for me.

 

There is only the form after this.

 

Can you see anything that could be making the error? Thanks again for help :)

I ran your code through "php -l" (php lint to check for errors) and the error I got was

Parse error: syntax error, unexpected T_IS_EQUAL, expecting ',' or ')' in x.php on line 25

Line 25 is

<?php
if (isset($_POST['username'] == '***') && ($_POST['password'] == '***')) {
?>

You are missing a closing ")" for the "isset" function. This line should be written as

<?php
if (isset($_POST['username']) == '***' && $_POST['password'] == '***') {
?>

I don't know what you're using as an editor, but get yourself one that shows matching "( )" and "{ }" at the very least.

 

Ken

This is the section of code I posted before:

 

if (isset($_POST['username'] == '***') && ($_POST['password'] == '***')) {

$_SESSION['username'] = 'login';    }

 

There is a closing ), where did you see this error?

 

Thanks :)

Ken is saying the isset method should only be checking your POST variable, not the entire condition.  But I think you might need another condition because if you use:

isset($_POST['username']) == '***'

then you're comparing the BOOL return value of isset to the string '***'.

Try:

 if (isset($_POST['username']) && $_POST['username'] == '***' && $_POST['password'] == '***') {

Thanks that has solved that problem but I was wondering whether yo could help me another problem it is now showing.

 

The error message reads:

 

Parse error: syntax error, unexpected $end in C:\wamp\www\admin.php on line 104

 

This is the same file I posted before plus this form:

<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>

<br> <br> 
</td>
<td width="1" bgcolor="lightskyblue" valign="top">   </td>
</tr></table>

</body>
</center>
</html>

 

Line 104 is the last line </html> any ideas would be really appreciated? Thanks :)

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.