【问题标题】:Parse error: syntax error, unexpected end of file in CODE on line 150 Errors parsing CODE解析错误:语法错误,第 150 行 CODE 中的文件意外结束 解析 CODE 错误
【发布时间】:2013-12-16 06:45:03
【问题描述】:

我一直在努力解决这个问题。我已经到处找了,无法解决这个问题。我不是一个很棒的编码器,所以我真的不知道出了什么问题。我问了几个人,他们帮助我解决了其他错误,然后出现了,他们无能为力。这是一个又一个错误,请帮助。这是 wordpress 只是为了提供一点帮助。

    <?php session_start(); ?>
<?php
/*
Template Name: test
*/
?>

<?php get_header(); ?>

<?php get_template_part( 'framework/inc/titlebar' ); ?>

<div id='page-wrap' class='container'>

        <div id='content' class='sidebar-right twelve columns'>
        <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

                <article id='post-<?php the_ID(); ?>' <?php post_class(); ?>>

                        <div class='entry'>

                                <?php the_content(); ?>

                                <?php wp_link_pages(array('before' => 'Pages: ', 'next_or_number' => 'number')); ?>

                        </div>

                </article>

                <?php if(!$data['check_disablecomments']) { ?>
                        <?php comments_template(); ?>
                <?php } ?>


        </div> <!-- end content -->


        <?php
/*** begin our session ***/

/*** first check that both the username, password and form token have been sent ***/
if(!isset( $_POST['phpro_username'], $_POST['phpro_password'], $_POST['form_token']))
{
    $message = 'Please enter a valid username and password';
}
/*** check the form token is valid ***/
elseif( $_POST['form_token'] != $_SESSION['form_token'])
{
    $message = 'Invalid form submission';
}
/*** check the username is the correct length ***/
elseif (strlen( $_POST['phpro_username']) > 20 || strlen($_POST['phpro_username']) < 4)
{
    $message = 'Incorrect Length for Username';
}
/*** check the password is the correct length ***/
elseif (strlen( $_POST['phpro_password']) > 20 || strlen($_POST['phpro_password']) < 4)
{
    $message = 'Incorrect Length for Password';
}
/*** check the username has only alpha numeric characters ***/
elseif (ctype_alnum($_POST['phpro_username']) != true)
{
    /*** if there is no match ***/
    $message = 'Username must be alpha numeric';
}
/*** check the password has only alpha numeric characters ***/
elseif (ctype_alnum($_POST['phpro_password']) != true)
{
        /*** if there is no match ***/
        $message = 'Password must be alpha numeric';
}
else
{
    /*** if we are here the data is valid and we can insert it into database ***/
    $phpro_username = filter_var($_POST['phpro_username'], FILTER_SANITIZE_STRING);
    $phpro_password = filter_var($_POST['phpro_password'], FILTER_SANITIZE_STRING);

    /*** now we can encrypt the password ***/
    $phpro_password = sha1( $phpro_password );

    /*** connect to database ***/
    /*** mysql hostname ***/
    $mysql_hostname = 'localhost';

    /*** mysql username ***/
    $mysql_username = ‘test_user’;

    /*** mysql password ***/
    $mysql_password = 'test';

    /*** database name ***/
    $mysql_dbname = ‘test;

    try
    {
        $dbh = new PDO("mysql:host=localhost;dbname=test", test, "test");

 /*** $message = a message saying we have connected ***/

        /*** set the error mode to excptions ***/
        $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

        /*** prepare the insert ***/
        $stmt = $dbh->prepare('INSERT INTO phpro_users (phpro_username, phpro_password ) VALUES (:phpro_username, :phpro_password )');

        /*** bind the parameters ***/
        $stmt->bindParam(':phpro_username', $phpro_username, PDO::PARAM_STR);
        $stmt->bindParam(':phpro_password', $phpro_password, PDO::PARAM_STR, 40);

        /*** execute the prepared statement ***/
        $stmt->execute();

        /*** unset the form token session variable ***/
        unset( $_SESSION['form_token'] );

        /*** if all is done, say thanks ***/


header("Location: aconfirmation);

   catch(Exception $e)
    {
        /*** check if the username already exists ***/
        if( $e->getCode() == 23000)
        {
            $message = 'Username already exists';
        }
        else
        {
            /*** if we are here, something has gone wrong with the database ***/
            $message = 'We are unable to process your request. Please try again later';
        }
    }
}
?>

<html>
<head>
<title>Affiliate</title>
</head>
<body>
<p><?php echo $message; ?>
</body>
</html>


</div> <!-- end page-wrap -->

<?php get_footer(); ?>

【问题讨论】:

    标签: php wordpress parsing syntax


    【解决方案1】:

    主要问题:

    您的 while 循环没有 endwhile 语句。将此添加到适当的位置

    <?php endwhile;?>    // This goes where loop has to end
    

    其他问题

    1

    header("Location: aconfirmation);
    

    缺少"

    header("Location: aconfirmation");
    

    2

    try 块没有结束 }

    这也会导致剩余的错误。但你知道有什么好笑的吗?我不必仔细阅读您的所有代码,我只是从 SO 语法荧光笔那里获得帮助,然后注意到明显错误的地方,您也可以在提交问题之前使用它来为您带来好处。

    【讨论】:

    • 有趣的是我做你的语法荧光笔。报价不是我的问题,我在编辑我的信息时不小心把它编辑掉了。引号在那里,没有解决问题。不过感谢您的帮助。如果您知道如何解决我当前的问题,请提供帮助。
    • 虽然我们只能根据提供的信息来回答,因此错误的编辑也可能会导致答案丢失,因此我们在提问时必须格外小心地正确复制我们的问题。话虽如此,请查看更新后的答案,您将获得所需的答案。干杯
    • @hanky-panky 我这样做了,它给了我这个错误 Parse error: syntax error, unexpected '}' in CODE on line 135 Errors parsing CODE,我删除了那个然后它又回到了页脚错误。有什么想法吗?
    • 你把它放在哪里了?就在标头调用之后?
    • 你介意解释一下我应该把它放在哪里吗?我还在学习 php,我会很感激它,所以我知道把它放在哪里以供将来参考,如果你不介意的话,就像上面显示的 endwhile 语句一样。
    【解决方案2】:

    你缺少一个花括号和一个引号

        header("Location: aconfirmation"); // <-- HERE
    } // <-- HERE
    catch(Exception $e)
    {
    

    【讨论】:

    • 是的,我知道,那是我在编辑代码以编辑我的信息时偶然发生的。这不是我的问题,但谢谢。
    猜你喜欢
    • 1970-01-01
    • 2013-02-03
    • 2013-07-12
    • 1970-01-01
    • 2018-01-02
    • 2013-01-23
    • 2017-06-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多