Php T_字符串分析错误

Php T_字符串分析错误,php,syntax-error,Php,Syntax Error,我有一个向数据库添加新学生的表单和一个名为NewStudentAddv2.php的php脚本 <?php require_once( "myfunctions.php" ); try { /** * ** connect using the getConnection function written in myfunctions.php ** */ $db = getConnection(); // *****************

我有一个向数据库添加新学生的表单和一个名为NewStudentAddv2.php的php脚本

<?php
require_once( "myfunctions.php" );
try {
    /**
     * ** connect using the getConnection function written in myfunctions.php **
     */
    $db = getConnection();

        // ********************************
        // *** SAVE THE STUDENT DETAILS ***
        // ********************************

        echo "<h2>New Student</h2>\n";

        $forename = $_POST['forename'];
        $surname = $_POST['surname'];
        $studytypeID = $_POST['studytypeID'];
        $startyear = $_POST['startyear'];

        // Determine the first character for a new student code.

        $yrCodes = array('07' => 'S', '08' => 'T', '09' => 'V', '10' => 'W);
        $yr = substr($startyear, 3, 2);     // Extract the last 2 digits from the year.
        $code = $yrCodes[$yr];      // Get the corresponding letter from the array.
        $today = getdate();             // Get the current date (returns an associated array).

        // Extract the day, month and year from the date and pad each string
        // to 2 characters (leading zero).

        $day = str_pad($today['mday'], 2, "0", STR_PAD_LEFT); //SYNTAX ERROR
        $mth = str_pad($today['mon'], 2, "0", STR_PAD_LEFT);
        $year = substr($today['year'], 2,2);

        $code .= $day.$mth.$year;   // Create a new student code.


        // Formulate a string containing the SQL INSERT statement.
        // NOTE: Only the values corresponding to character fields in the
        // database table are delimited with ' '. Values for numeric
        //fields do not need to be delimited.

        $sql = "INSERT INTO student (studentCode, forename, surname, studytypeID, startyear) VALUES 
        (:code, :forename, :surname, :studytypeID, :startyear)";

        $stmt = $db->prepare($sql);
        $stmt->bindParam(':code', $code, PDO::PARAM_STR);
        $stmt->bindParam(':forename', $forename, PDO::PARAM_STR );
        $stmt->bindParam(':surname', $surname, PDO::PARAM_STR );
        $stmt->bindParam(':studytypeID', $studytypeID);
        $stmt->bindParam(':startyear', $startyear);

        // Parse the SQL statement.
        $stmt->execute();
        }
        catch( PDOException $e ) {
            // Handle an error, if any.
            echo "<p><strong>Error:</strong> The details for student '$forename $surname' \n";
            echo "have not be saved in the database. Please consult the system administrator \n";
            echo "with the error message '".$e->getMessage()."'.</p>\n";  
        }
                // Display 'success' message to the user.
        echo "<p>The details for student '$forename $surname: $code, $studytypeID, $startyear' have successfully been saved \n";
        echo "to the database.</p>\n";

        echo "<p><a href=\"NewStudentForm.php\">Enter a new student</a>\n</p>";
    ?>
提交表格时,我会遇到

分析错误:语法错误,意外的T_字符串,在第40行的/var/www/vhosts/numyspace.co.uk/web_users/home/~unn_w11026991/public_html/NewStudentAddv2.php中应为“')

NewStudentAddv2.php

<?php
require_once( "myfunctions.php" );
try {
    /**
     * ** connect using the getConnection function written in myfunctions.php **
     */
    $db = getConnection();

        // ********************************
        // *** SAVE THE STUDENT DETAILS ***
        // ********************************

        echo "<h2>New Student</h2>\n";

        $forename = $_POST['forename'];
        $surname = $_POST['surname'];
        $studytypeID = $_POST['studytypeID'];
        $startyear = $_POST['startyear'];

        // Determine the first character for a new student code.

        $yrCodes = array('07' => 'S', '08' => 'T', '09' => 'V', '10' => 'W);
        $yr = substr($startyear, 3, 2);     // Extract the last 2 digits from the year.
        $code = $yrCodes[$yr];      // Get the corresponding letter from the array.
        $today = getdate();             // Get the current date (returns an associated array).

        // Extract the day, month and year from the date and pad each string
        // to 2 characters (leading zero).

        $day = str_pad($today['mday'], 2, "0", STR_PAD_LEFT); //SYNTAX ERROR
        $mth = str_pad($today['mon'], 2, "0", STR_PAD_LEFT);
        $year = substr($today['year'], 2,2);

        $code .= $day.$mth.$year;   // Create a new student code.


        // Formulate a string containing the SQL INSERT statement.
        // NOTE: Only the values corresponding to character fields in the
        // database table are delimited with ' '. Values for numeric
        //fields do not need to be delimited.

        $sql = "INSERT INTO student (studentCode, forename, surname, studytypeID, startyear) VALUES 
        (:code, :forename, :surname, :studytypeID, :startyear)";

        $stmt = $db->prepare($sql);
        $stmt->bindParam(':code', $code, PDO::PARAM_STR);
        $stmt->bindParam(':forename', $forename, PDO::PARAM_STR );
        $stmt->bindParam(':surname', $surname, PDO::PARAM_STR );
        $stmt->bindParam(':studytypeID', $studytypeID);
        $stmt->bindParam(':startyear', $startyear);

        // Parse the SQL statement.
        $stmt->execute();
        }
        catch( PDOException $e ) {
            // Handle an error, if any.
            echo "<p><strong>Error:</strong> The details for student '$forename $surname' \n";
            echo "have not be saved in the database. Please consult the system administrator \n";
            echo "with the error message '".$e->getMessage()."'.</p>\n";  
        }
                // Display 'success' message to the user.
        echo "<p>The details for student '$forename $surname: $code, $studytypeID, $startyear' have successfully been saved \n";
        echo "to the database.</p>\n";

        echo "<p><a href=\"NewStudentForm.php\">Enter a new student</a>\n</p>";
    ?>
我是新的PHP,似乎看不到错误,任何帮助将不胜感激

$yrCodes = array('07' => 'S', '08' => 'T', '09' => 'V', '10' => 'W); 
缺少报价

$yrCodes = array('07' => 'S', '08' => 'T', '09' => 'V', '10' => 'W'); 
PHP认为以“'W”开头的带引号的字符串跨越多行,并在第40行中以“$today['”结尾,使mday成为下一个代码标记……由于此ais不是有效的代码标记,而是字符串,因此会出现意外的T_字符串错误

缺少报价

$yrCodes = array('07' => 'S', '08' => 'T', '09' => 'V', '10' => 'W'); 

PHP认为以“'W”开头的带引号的字符串跨越多行,并以“$today[”结尾在第40行中,使mday成为下一个代码标记…由于此ais不是有效的代码标记,而是字符串,因此您会遇到意外的T_字符串错误

如果您使用具有正确语法高亮显示的编辑器,这些错误很快就会变得明显。这只是进一步编码的提示。我使用的是Dreamweaver CS5,刚刚注意到在MITA之后高亮显示的变化ke被纠正了,谢谢你的建议。如果你使用一个具有正确语法突出显示的编辑器,这些错误很快就会变得明显。作为进一步编码的提示。我使用的是Dreamweaver CS5,刚刚注意到错误纠正后突出显示的变化,谢谢你的建议。谢谢,不敢相信我错过了。谢谢,不能我想我错过了。