Jump to content
Larry Ullman's Book Forums

Script 8.3 Parse Error Message - Help


Recommended Posts

I'm getting this error message when I try to open register.php in the browser:

 

Parse error: syntax error, unexpected 'isset' (T_ISSET), expecting '(' in /Applications/mampstack-5.4.10-0/apache2/htdocs/register.php on line 90

 

Here's the section of code around line 90 (starting at line 75 and ending at line 92, the last isset location):

 

    } else { // Report the errors.
    
        echo '<h1>Error!</h1>
        <p class="error">The following error(s) occurred:<br />';
        foreach ($errors as $msg) { // Print each error.
            echo " - $msg<br />\n";
        }
        echo '</p><p>Please try again.</p><p><br /></p>';
        
    } // End of if (empty($errors)) IF.

} // End of the main Submit conditional.
?>
<h1>Register</h1>
<form action="register.php" method="post">
    <p>First Name: <input type="text" name="first_name" size="15" maxlength="20" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p>
    <p>Last Name: <input type="text" name="last_name" size="15" maxlength="40" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></p>
    <p>Email Address: <input type="text" name="email" size="20" maxlength="80" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>"  /> </p>

 

This is the weird part: I then saved MY script as register1.php, then copied and pasted Larry's script from the downloads folder into the register.php file (after comparing my script with Larry's and finding 1 error much higher in the script), overwriting my own script, then tried to open it in the browser. Same error message. (The code above is from Larry's code.)

 

I'm running PHP 5.4.10-0 and MySql 5.0.10 on a Bitnami MAMPstack.

 

Thoughts?

Link to comment
Share on other sites

It's obviously a parse error, and probably connected to a logical test including a call to isset().

 

You only post parts of your code here, so it's difficult to find the specific part that causes the error. The easiest solution is to get an IDE with error highlightning. Try downloading Eclipse or Netbeans (Both free) and check your code there. It should tell you the line of code that causes the error.

 

I added the two missing if-clauses to make the script parse correctly. With those, the script is perfectly valid. I would consider looking more at those, as I suspect the error to be there.

 

Notice that the code above is not a solution to your problem. It only solves your parse errors. (And proving the rest of your code is free for parse errors.)

<?php
if ( true ) { // First missing if

    if ( true ) { // Second missing if
    
    } else { // Report the errors.
    
        echo '<h1>Error!</h1>
        <p class="error">The following error(s) occurred:<br />';
        foreach ($errors as $msg) { // Print each error.
            echo " - $msg<br />\n";
        }
        echo '</p><p>Please try again.</p><p><br /></p>';
        
    } // End of if (empty($errors)) IF.

} // End of the main Submit conditional.
?>
 
Link to comment
Share on other sites

Interestingly, as I said, even the author's code didn't work. I copied and pasted Larry's script into my file, and still an error message.

Eclipse never did install on my Mac (I tried about 3-4 months ago), and Netbeans is Java-based, which I've disabled.

I'll post the code from the 8.3 script in Larry's downloads folder:

 

<?php # Script 8.3 - register.php

$page_title = 'Register';
include ('includes/header.html');

// Check if the form has been submitted:
if (isset($_POST['submitted'])) {

    $errors = array(); // Initialize an error array.
    
    // Check for a first name:
    if (empty($_POST['first_name'])) {
        $errors[] = 'You forgot to enter your first name.';
    } else {
        $fn = trim($_POST['first_name']);
    }
    
    // Check for a last name:
    if (empty($_POST['last_name'])) {
        $errors[] = 'You forgot to enter your last name.';
    } else {
        $ln = trim($_POST['last_name']);
    }
    
    // Check for an email address:
    if (empty($_POST['email'])) {
        $errors[] = 'You forgot to enter your email address.';
    } else {
        $e = trim($_POST['email']);
    }
    
    // Check for a password and match against the confirmed password:
    if (!empty($_POST['pass1'])) {
        if ($_POST['pass1'] != $_POST['pass2']) {
            $errors[] = 'Your password did not match the confirmed password.';
        } else {
            $p = trim($_POST['pass1']);
        }
    } else {
        $errors[] = 'You forgot to enter your password.';
    }
    
    if (empty($errors)) { // If everything's OK.
    
        // Register the user in the database...
        
        require_once ('../mysqli_connect.php'); // Connect to the db.
        
        // Make the query:
        $q = "INSERT INTO users (first_name, last_name, email, pass, registration_date) VALUES ('$fn', '$ln', '$e', SHA1('$p'), NOW() )";        
        $r = @mysqli_query ($dbc, $q); // Run the query.
        if ($r) { // If it ran OK.
        
            // Print a message:
            echo '<h1>Thank you!</h1>
        <p>You are now registered. In Chapter 11 you will actually be able to log in!</p><p><br /></p>';    
        
        } else { // If it did not run OK.
            
            // Public message:
            echo '<h1>System Error</h1>
            <p class="error">You could not be registered due to a system error. We apologize for any inconvenience.</p>';
            
            // Debugging message:
            echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $q . '</p>';
                        
        } // End of if ($r) IF.
        
        mysqli_close($dbc); // Close the database connection.
        
        // Include the footer and quit the script:
        include ('includes/footer.html');
        exit();
        
    } else { // Report the errors.
    
        echo '<h1>Error!</h1>
        <p class="error">The following error(s) occurred:<br />';
        foreach ($errors as $msg) { // Print each error.
            echo " - $msg<br />\n";
        }
        echo '</p><p>Please try again.</p><p><br /></p>';
        
    } // End of if (empty($errors)) IF.

} // End of the main Submit conditional.
?>
<h1>Register</h1>
<form action="register.php" method="post">
    <p>First Name: <input type="text" name="first_name" size="15" maxlength="20" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p>
    <p>Last Name: <input type="text" name="last_name" size="15" maxlength="40" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></p>
    <p>Email Address: <input type="text" name="email" size="20" maxlength="80" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>"  /> </p>
    <p>Password: <input type="password" name="pass1" size="10" maxlength="20" /></p>
    <p>Confirm Password: <input type="password" name="pass2" size="10" maxlength="20" /></p>
    <p><input type="submit" name="submit" value="Register" /></p>
    <input type="hidden" name="submitted" value="TRUE" />
</form>
<?php
include ('includes/footer.html');
?>



 

Link to comment
Share on other sites

Sorry about that. We have a different timezone here in Europe. I should not post while drunk. As a Juventus fan (If any of follow (real) Football (or Soccer)) my team won just some hours ago an important match...

 

However. I tried your script one more time, making sure of the file name. I receive no errors when posting here, only a blank screen. (which makes sense following your logic) This does not correlate to the parse error you received. Are you sure this is the exact same version you are posting to? A parse error is triggered regardless of status (successful posting/errors received) and is thereby not tied to logic. 

 

Did you solve the error?

Link to comment
Share on other sites

LOL! Yes, it's resolved, more or less. I downloaded the downloads folder for the book, cleared my caches AGAIN in FF and Safari, deleted my script, copied and pasted Larry's script, and after the first time of getting an "unexpected end of line error," I was able to get the script to run the second time. Now I'm going to try to recode the script from scratch again. I was using TextWrangler - the free version of BBEdit, and I don't know what was going on.

 

I've downloaded Netbeans and have absolutely no idea how to set up a PHP project in it (I watched the Quickstart tutorial, but at one point, my screen was asking for info that wasn't on the screen in the tutorial, even making allowances for my being on a Mac in it - it kept asking for a PHP framework). WAY too confusing at this time, and it's unlikely I'll find documentation for NetBeans on my Mac. i could install NetBeans on my virtual machine running Win7, but that's kinda sluggish.

I've downloaded Zend Eclipse PDT. We'll see if that's any better. The Eclipse Classic (Mac version) does bad things to my Mac running Lion. I've also downloaded Aptana and Komodo and will play with those.
 

Congrats on your team winning!

Link to comment
Share on other sites

Projects are simply structures to organize folders. It's very easy once you get the hang of it. Your problem might be that you don't have the PHP version? You should be able to add a "PHP project". When that is done, just think of it as a main folder organizing your code.

 

Glad you solved the problem.

 

Thanks btw. It was a good match!

Link to comment
Share on other sites

No, I have th PHP version, I could see PHP as one its options, but it kept asking for which PHP framework I wanted, which I then had to install. I installed Zend Eclipse PDT, and that's better. Aptana only goes up to PHP 5.3, and they've been working on adding support for 5.4 for over a year, based on the info I found out during a Google search. That looks like a pretty great IDE, except for that.

Link to comment
Share on other sites

 Share

×
×
  • Create New...