chicago Posted March 29, 2011 Share Posted March 29, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/232073-re-parse-error-syntax-error-unexpected-t_string-expecting-or/ Share on other sites More sharing options...
kenrbnsn Posted March 29, 2011 Share Posted March 29, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/232073-re-parse-error-syntax-error-unexpected-t_string-expecting-or/#findComment-1193716 Share on other sites More sharing options...
Maq Posted March 29, 2011 Share Posted March 29, 2011 @chicago, next time follow what ken posted. I split your topic this time, so you do not have to start a new thread, but please do in the future. Quote Link to comment https://forums.phpfreaks.com/topic/232073-re-parse-error-syntax-error-unexpected-t_string-expecting-or/#findComment-1193724 Share on other sites More sharing options...
chicago Posted March 30, 2011 Author Share Posted March 30, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/232073-re-parse-error-syntax-error-unexpected-t_string-expecting-or/#findComment-1194184 Share on other sites More sharing options...
gizmola Posted March 30, 2011 Share Posted March 30, 2011 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.. Quote Link to comment https://forums.phpfreaks.com/topic/232073-re-parse-error-syntax-error-unexpected-t_string-expecting-or/#findComment-1194189 Share on other sites More sharing options...
chicago Posted March 30, 2011 Author Share Posted March 30, 2011 I have counted all the curly brackets and every one that is opened also closes, thats what I thought the problem was. Any other ideas? Thanks for replying Quote Link to comment https://forums.phpfreaks.com/topic/232073-re-parse-error-syntax-error-unexpected-t_string-expecting-or/#findComment-1194199 Share on other sites More sharing options...
gizmola Posted March 30, 2011 Share Posted March 30, 2011 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'])." Quote Link to comment https://forums.phpfreaks.com/topic/232073-re-parse-error-syntax-error-unexpected-t_string-expecting-or/#findComment-1194209 Share on other sites More sharing options...
chicago Posted March 30, 2011 Author Share Posted March 30, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/232073-re-parse-error-syntax-error-unexpected-t_string-expecting-or/#findComment-1194241 Share on other sites More sharing options...
kenrbnsn Posted March 30, 2011 Share Posted March 30, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/232073-re-parse-error-syntax-error-unexpected-t_string-expecting-or/#findComment-1194361 Share on other sites More sharing options...
chicago Posted March 30, 2011 Author Share Posted March 30, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/232073-re-parse-error-syntax-error-unexpected-t_string-expecting-or/#findComment-1194452 Share on other sites More sharing options...
Maq Posted March 30, 2011 Share Posted March 30, 2011 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'] == '***') { Quote Link to comment https://forums.phpfreaks.com/topic/232073-re-parse-error-syntax-error-unexpected-t_string-expecting-or/#findComment-1194457 Share on other sites More sharing options...
chicago Posted March 30, 2011 Author Share Posted March 30, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/232073-re-parse-error-syntax-error-unexpected-t_string-expecting-or/#findComment-1194550 Share on other sites More sharing options...
betterphp Posted March 30, 2011 Share Posted March 30, 2011 that usually means you have a missing } Quote Link to comment https://forums.phpfreaks.com/topic/232073-re-parse-error-syntax-error-unexpected-t_string-expecting-or/#findComment-1194551 Share on other sites More sharing options...
Maq Posted March 30, 2011 Share Posted March 30, 2011 As betterphp said, this usually means you're missing a terminating '}'. If you properly format/indent your php code then you would probably be able to see where the missing brace occurs. Quote Link to comment https://forums.phpfreaks.com/topic/232073-re-parse-error-syntax-error-unexpected-t_string-expecting-or/#findComment-1194553 Share on other sites More sharing options...
salathe Posted March 30, 2011 Share Posted March 30, 2011 chicago, you never end this block: if ($_SESSION['username']=='login') { Quote Link to comment https://forums.phpfreaks.com/topic/232073-re-parse-error-syntax-error-unexpected-t_string-expecting-or/#findComment-1194626 Share on other sites More sharing options...
chicago Posted March 31, 2011 Author Share Posted March 31, 2011 Thanks a lot everyone, I can't believed I missed the } Quote Link to comment https://forums.phpfreaks.com/topic/232073-re-parse-error-syntax-error-unexpected-t_string-expecting-or/#findComment-1194829 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.