开发者

Parse error: syntax error, unexpected T_CATCH in... on line 65?

The error occurs on line 65: } catch (Exception $e){

<?php

require "includes/connect.php";



function generateCode($length = 5)
{
    $characters = 'bcdfghjkmnpqrstvwxyz';
    $string = '';

    for ($i = 0; $i < $length; $i++) {
        $string .= $characters[rand(0, strlen($characters) - 1)];
    }
    return $string;
}


$msg = '';


if($_POST['email']) {

    // Requested with AJAX:
    $ajax = ($_SERVER['HTTP_X_REQUESTED_WITH']  == 'XMLHttpRequest');


    try {

        if(!filter_input(INPUT_POST,'email',FILTER_VALIDATE_EMAIL)){
            throw new Exception('Invalid Email!');
        }

        if($ajax){
            die('{"status":1}');
        }

        $unique_code = "";
        $inserted =开发者_如何转开发 false;

        // Keep looping until we've inserted a record
        while(!$inserted) {

            // Generate a code
            $unique_code = generateCode();

            // Check if it exists
            if ($result = $mysqli->query("SELECT unique_code FROM coming_soon_emails WHERE unique_code = '$unique_code'")) {

            // Check no record exists
            if ($result->num_rows == 0) {

                // Create new record
                $mysqli->query("INSERT INTO coming_soon_emails (email,unique_code) VALUES ('" . $mysqli->real_escape_string($_POST['email']) . "','$unique_code')");

                // Set inserted to true to ext loop
                $inserted = true;

                // Close the result object
                $result->close();
            }
        }

    } catch (Exception $e){

        if($ajax){
            die(json_encode(array('error'=>$e->getMessage())));
        }

        $msg = $e->getMessage();
        die($msg);
    }      

} else {
    // Quit if we can't check the database
    die('Something went wrong with select');
}   



?>


Your braces don't match up. Your while loop does not have a proper matching brace at the end (after the two if statements)... just add a } before the catch line.

You should get something like Notepad++ to write PHP with!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜