Impossible Parse Error

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

User avatar
llanitedave
Forum Commoner
Posts: 78
Joined: Thu Jan 15, 2004 11:24 am
Location: Las Vegas, NV.

Impossible Parse Error

Post by llanitedave »

OK, I really can't figure this one out.

My page has 8 different <?php ... ?> blocks.

The very last one looks like this:

Code: Select all

<?php

// provide links for the footer

$foot_link1 = '<a href="User_Start.php">Return to My Start Page</a>';
$foot_link2 = '<a href="qc_logout.php">Log Out</a>';

include ('q_standard_footer.php');


?>
I'm getting a parse error, in both Safari and Mozilla, on the opening PHP tag itself!

I've checked all the preceding php blocks, and they are all complete. I've not done anything to this particular block, and it was working until today. In fact, the only change I've made to this page since the last time I tested it is to change a call to javascript function higher up. I don't see this having any effect on what's happening now.

Is there something in the engine itself that can be corrupted? I'm clueless!
User avatar
Ixplodestuff8
Forum Commoner
Posts: 60
Joined: Mon Feb 09, 2004 8:17 pm
Location: Queens, New York

Post by Ixplodestuff8 »

What is the code block over the one with the error, and what exactly is the actual error message?
User avatar
llanitedave
Forum Commoner
Posts: 78
Joined: Thu Jan 15, 2004 11:24 am
Location: Las Vegas, NV.

Post by llanitedave »

The message is:
"Parse error: parse error in /Library/Apache2/htdocs/my_app_folder/my_account.php on line 123"

Not too informative, I know. As for previous php blocks, I have several in-line short blocks embedded in an html table. The two preceding the error-calling block are:

<h3>My total logins: <?php echo $login_num; ?></h3>
<h3 style="font-style: italic">My lifetime total time logged on: <?php echo $total_time; ?></h3>

Both the $login_num and $total_time variables are valid.
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post by Dale »

erm maybe the " need \"

Try this:

Code: Select all

<?php 

// provide links for the footer 

$foot_link1 = '<a href="User_Start.php">Return to My Start Page</a>'; 
$foot_link2 = '<a href="qc_logout.php">Log Out</a>'; 

include ('q_standard_footer.php'); 


?>
Maybe thats what you wanted maybes its not...
mikegotnaild
Forum Contributor
Posts: 173
Joined: Sat Feb 14, 2004 5:59 pm

Post by mikegotnaild »

most likely
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Shouldn't need to escape those as they are in single quotes. Eg echo 'some "text" here'; is fine, but you would need to escape them with echo "some "text" here"; ( echo "some \"text\" here"; )
evilMind
Forum Contributor
Posts: 145
Joined: Fri Sep 19, 2003 10:09 am
Location: Earth

Re: Impossible Parse Error

Post by evilMind »

llanitedave wrote: I've checked all the preceding php blocks, and they are all complete. I've not done anything to this particular block, and it was working until today. In fact, the only change I've made to this page since the last time I tested it is to change a call to javascript function higher up. I don't see this having any effect on what's happening now.
Have you tried removing that js call to see if it works then? Also, what is on line 123 where you have reported the error is occuring? Is that the include statement? If so you may need to check the 'q_standard_footer.php' file to see if it could be the cause of your anguish.
User avatar
llanitedave
Forum Commoner
Posts: 78
Joined: Thu Jan 15, 2004 11:24 am
Location: Las Vegas, NV.

Post by llanitedave »

Thanks for the ideas, all, but none of them are helping. Line 123, where the parse error is occuring, is the "<?php" tag itself!

I'm going to remove the block this afternoon, and close the table with straight html in the active file, and see if that helps.

I'll let you know what I find. I'm sure it will be something stupid that I did, but I can't imagine what at this point.
phuts
Forum Newbie
Posts: 15
Joined: Thu Feb 19, 2004 12:29 am
Location: Ohio, USA

Post by phuts »

llanitedave wrote:Line 123, where the parse error is occuring, is the "<?php" tag itself!
It sounds to me like the syntax error is above line 123, just as you get a parse error on the next line if you forget a ";"
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Show us your whole code and comment the line 123
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post by Dale »

Image Hey markl999 ;)

markl999 wrote:Shouldn't need to escape those as they are in single quotes. Eg echo 'some "text" here'; is fine, but you would need to escape them with echo "some "text" here"; ( echo "some "text" here"; )

Oh true... :D
User avatar
llanitedave
Forum Commoner
Posts: 78
Joined: Thu Jan 15, 2004 11:24 am
Location: Las Vegas, NV.

Post by llanitedave »

Phenom wrote:Show us your whole code and comment the line 123
OK, here's the file:

Code: Select all

<?php
 // qc_My_account.php  Allows operator to update password and view status
include_once ('my_session_start.php');
include_once ('general_functions.php');
$page_Name = $_SESSION['full_name'].":  My Update Page";
include ('q_standard_header.php');
?>
<script language="Javascript" type="text/javascript">
  
  <!--  Hide script from older browsers
  
function checkform(userChangeForm) {
    if (userChangeForm.newPassword2.value != "") { // If a new password is submitted
	   if (userChangeForm.newPassword2.value != userChangeForm.newPassword1.value) { // passwords don't match
		  if (userChangeForm.newPassword1.value = "" or userChangeForm.oldPassword.value = "") { // blank password
				alert("All password fields must be filled out!")
		  } else {
			 alert("Passwords don't match!  Try again!")
		  }
	   }
	   userChangeForm.oldPassword.focus()
	   return false
    }
      
    if (userChangeForm.answer.value != "") and (userChangeForm.question.value = ""){ // if the hint is being changed and no question exists
	   alert("Please enter a question for your hint")
	   userChangeForm.question.focus()
	   return false
    }
      
    return true
}
    
    // end hiding script -->
    
</script>

<?php
// do some data validation stuff
if ($_POST['newPassword2'] or $_POST['answer']) {  //  User has changed personal info

    if ($_POST['newPassword2']) { // password changed
        
	   // check both passwords to make sure they match
	   // this should be done by the javascript first, but that might not be enabled...
	   if ($_POST['newPassword1'] != $_POST['newPassword2']) {
	       $errorPass = "<h3>Could not change password:  The passwords entered don't match.</h3>";
	   } else {
	   
        // check to make sure the old password is correct
        $old_pass = md5(trim($_POST['oldPassword']));	   
        $sql = "select userpassword from users where user_id = '".$_SESSION['user_id']."'";	   
        $result = mysql_query($sql) or die(mysql_error());	   
        $userdata = mysql_fetch_array($result);	   	   
        if ($userdata['userpassword'] != $old_pass) { // wrong password	   
            $errorPass = "<h3>Could not change password:  The Old password you entered was incorrect.</h3>";		  
        } else {
            $new_pass = md5(trim($_POST['newPassword2']));		  
            $update = "update users set userpassword = '$new_pass' where user_id = '".$_SESSION['user_id']."'";
            $result = mysql_query($update) or die(mysql_error());       
            $errorPass = "<h3>Password Changed successfully</h3>";
        }
    }
    
    if ($_POST['answer']) { // new password hint given changed
        
	   $new_hint = trim($_POST['question']);
        $answer = trim($_POST['answer']);
        $update = "update users set (pass_hint = '$new_hint', hint_answer = '$answer') where user_id = '".$_SESSION['user_id']."'";
	   $result = mysql_query($update) or die(mysql_error());
	   if ($result) {
		  $getthehint = "<h3>Password Hint Changed successfully</h3>";
	   }	   
    }
}

// get the login information
$logins = "select * from user_logins where user_id = '".$_SESSION['user_id']."'";
$result = mysql_query($logins) or die(mysql_error());
$login_num = mysql_numrows($result); 

// get the total lifetime session time
$total_time = 0;
for ($count = 1; $count <= ($login_num - 1); $count = $count + 1) { // don't count the current login
    $login_row = mysql_fetch_array($result);
    $total_time = $total_time + ($login_row['logoff_time'] - $login_row['logon_time']);
}
$virtual_start = $_SESSION['login_time'] - $total_time; // this brings in the current login
$total_time = time_span(time(), $virtual_start);

?>
      <table cellpadding="2" cellspacing="1" border="0" style="width: 100%">
        <tr>
          <td style="text-align: left; color: rgb(114, 0, 0)">
          <h2>My User ID: <?php echo $_SESSION['username']; ?></h2>
          </td>
          <td style="text-align: right; color: rgb(114, 0, 0);">
          <h3>My Status: <?php echo $_SESSION['Auth_level']; ?></h3>
          
          </td>
        </tr>
      </table>
      <table cellpadding = "5" cellspacing="2" border="0" style="width: 90%">
          <tr>
              <td style="text-align: center; verticle-align: center; background-color: rgb(204, 204, 255); width: 50%"><br><h3>Change My Password</h3>
              </td>
          </tr>
          <form onsubmit="return checkform(this)" method="post" action="qc_My_account.php">
          <tr>
              <td style="text-align: right; verticle-align: center; background-color: rgb(204, 204, 255); width: 50%"><?php echo $errorPass ?>Old password: <input type="password" name="oldPassword"><br>
                  New Password: <input type = "password" name="newPassword1"><br>
                  Repeat New Password: <input type = "password" name="newPassword2"><br><br>
                  <hr>
                  <h3 style="font-style: italic; text-align: center">Enter a personal question that can serve as a hint in case you forget your password.  No one should know the answer to this question but you.</h3>
                  <div style="text-align: center">Question: </div>
               </td>
               <td style="text-align: center">
                   <h3>Time Logged in so far this session: <?php echo time_span(time(), $_SESSION['login_time']); ?></h3>
               </td>
           </tr>
           <tr>
              <td style="text-align: right; background-color: rgb(204, 204, 255); width: 50%"><textarea name="question" rows=4 cols=30></textarea><br>
               <br>
                  Your Answer: <input type="text" name="answer">
                  <br>
              </td>
              <td style="text-align: center">
                  <h3>My total logins: <?php echo $login_num; ?></h3>
                  <h3 style="font-style: italic">My lifetime total time logged on: <?php echo $total_time; ?></h3>
		    </td>
          </tr>
          <tr>
              <td style="text-align: left; verticle-align: center; background-color: rgb(204, 204, 255); width: 50%"><input type="submit" name="changePassword" value="Save Changes">&nbsp;<br>&nbsp;<br>
              </td>
          </tr>
          </form>
      </table>
<!-- the line below is line 123, according to the parser --->
<?php
/**** the line above was line 123, acording to the parser ****/
// provide links for the footer

$foot_link1 = '<a href="User_Start.php">Return to My Start Page</a>';
$foot_link2 = '<a href="qc_logout.php">Log Out</a>';

include ('q_standard_footer.php');


?>
Any guidance or ideas you can give would be GREATLY appreciated!
User avatar
redhair
Forum Contributor
Posts: 300
Joined: Fri May 30, 2003 4:36 pm
Location: 53.23N-6.57E
Contact:

Post by redhair »

Add a } on line 39 or 53?
User avatar
redhair
Forum Contributor
Posts: 300
Joined: Fri May 30, 2003 4:36 pm
Location: 53.23N-6.57E
Contact:

Post by redhair »

You also forgot a ; in <?php echo $errorPass ?>
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

You also forgot a ; in <?php echo $errorPass ?>
Just to note that you should put the ; in just for consistencies sake, but that it's not required. A ; is implied if followed by ?>
Post Reply