2012-02-22 59 views
0

我提交我我會見了T_STRING解析錯誤

Parse error: syntax error, unexpected T_STRING, expecting ')' in /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_w11026991/public_html/NewStudentAddv2.php on line 40

NewStudentAddv2.php

表單時增加新的學生數據庫,並呼籲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>"; 
    ?> 

線40

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

我是PHP新手,似乎無法看到錯誤,任何幫助將不勝感激。

+0

如果使用正確語法高亮顯示的編輯器,此類錯誤很快就會變得明顯。就像進一步編碼的提示一樣。 – Sirko 2012-02-22 10:21:27

+0

我使用的Dreamweaver CS5,只是注意到一旦錯誤被糾正突出顯示的變化,感謝您的建議。 – 2012-02-22 10:28:43

回答

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

缺失報價

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

PHP認爲,隨着「開頭的引號的字符串「W」跨越多行,並以「今天$ [關閉的引號結束」的第40行」使mday成爲下一個代碼令牌....因爲這不是一個有效的代碼令牌,而是一個字符串,所以會出現意外的T_STRING錯誤

+0

謝謝,不能相信我錯過了。 – 2012-02-22 10:23:03

相關問題