2012-12-13 101 views
0

我一直在試圖爲一個組創建一個網站,但我遇到了一些錯誤,我似乎無法修復自己。我的問題是,如果你們中的一些人能夠發現我做錯了什麼,我一直在尋找,似乎無法找到任何開放或任何相似的東西。解析錯誤:語法錯誤,意外的文件結尾

在此先感謝

<?php 
session_start(); 

//Loading template power 
include_once("../attritiongaming/tpl/class.TemplatePower.inc"); 

//Linking templatepower to html 
$tpl = new TemplatePower("test.html"); 

//Connecting to database 
$db = new PDO('mysql:host=localhost;dbname=attritiongaming','root', 'solidusaphm8932'); 
    $db ->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 

$tpl->assign("name", "Jessey"); 

//Echo tables 
echo 
"<table border='1'> 
<tr> 
<th>ID</th> 
<th>firstname</th> 
<th>lastname</th> 
<th>username</th> 
<th>emailadress</th> 
<th>edit</th> 
<th>remove</th> 
</tr>"; 

//defining page 
$page = isset($_GET['action']) ? $_GET['action'] : ''; 

//Start switch for page 
switch ($page) 
    { 
    case 'edit'; 

     $tpl->newBlock("edit"); 

    try 
{ 
    $db = new PDO('mysql:host=localhost;dbname=attritiongaming','root', 'solidusaphm8932'); 
    $db ->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 

    $sql ="UPDATE members SET firstname='firstname' WHERE firstname='jessey'"; 

    //Secure with PDO 
    $stmt = $db->prepare($sql); 

    $stmt->bindParam(':firstname', $firstname, PDO::PARAM_STR); 
    $stmt->bindParam(':lastname', $lastname, PDO::PARAM_STR); 
    $stmt->bindParam(':username', $username, PDO::PARAM_STR); 
    $stmt->bindParam(':emailadress', $emailadress, PDO::PARAM_STR); 
    $stmt->bindParam(':password', $password, PDO::PARAM_STR); 

    //execute sql query 
    $stmt->execute(); 
} 

//Catch errors and show them. 
catch(PDOException $e) 
{ 
    echo '<pre>'; 
    echo 'line '.$e->getLine().'<br>'; 
    echo 'file'.$e->getFile().'<br>'; 
    echo 'Error'.$e->getMessage(); 
    echo '</pre>'; 
} 

    default: 

    $tpl->newBlock("default"); 

    if (isset($_POST['search'])) 
    { 
    $tpl->assign("searchterm", $_POST['search']); 
    } 

if (isset($_POST['searching'])) 
{ 
    $sql ="SELECT * FROM members WHERE username LIKE :search"; 

    $stmt = $db->prepare($sql); 

    $search = $_POST['search']. '%'; 

    $stmt->bindParam(':search', $search, PDO::PARAM_STR); 

    $stmt->execute(); 
} 
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) 
    { 
    $tpl->newBlock(""); 
    } 

    $sql= "SELECT * FROM members"; 
$stmt=$db->prepare($sql); 

$stmt->execute(); 

    //Loop show all members 
    while($row = $stmt->fetch(PDO::FETCH_ASSOC)) 
    { 
    echo "<tr>"; 
    echo "<td>" . $row['ID'] . "</td>"; 
    echo "<td>" . $row['firstname'] . "</td>"; 
    echo "<td>" . $row['lastname'] . "</td>"; 
    echo "<td>" . $row['username'] . "</td>"; 
    echo "<td>" . $row['emailadress'] . "</td>"; 
    echo "<td> <a href='?action=edit&id=".$row['ID']."'>Edit</a></td>"; 
    echo "<td> <a href='?action=remove&id=".$row['ID']."'>Remove</a></td>"; 
    echo "</tr>"; 
    } 

?> 
+1

可能缺少一個} - 使用一個編輯器或者IDE來匹配大括號,或者(至少)不錯的縮進 –

+2

你錯過了'switch'語句的結尾符號,把'}'放在末尾 – vlcekmi3

+0

<?php missing in代碼 –

回答

3

你沒有關閉開關並沒有「破發」在默認情況下結束

+0

你的意思是默認情況下的權利?在默認情況下不需要中斷。 – jValdron

+1

在案例中使用break總是一個好主意。 – Lenin

0

開關的情況下右括號未閉合

相關問題