2015-07-03 19 views
-2

我想顯示的數據從一個MySQL數據的HTML數據,並觀看了視頻,並跟着他們只改變什麼是必要的像表名數據庫名稱等。 我不斷收到此錯誤?簡單的MYSQL數據不顯示致命錯誤

解析錯誤:語法錯誤,意想不到 '$ SQL'(T_VARIABLE)在C:\ XAMPP \ htdocs中\ keytracker \ keytracker.php上線37

<html> 
<head> 
<title>SRE | Key Tracker</title> 
<link rel = "stylesheet" type="text/css" href="style.css"> 
</head> 
<body> 
<div class="searchandregister"> 
<h2 class="cat-title">Search Booked Keys</h2> 
<form method="POST" action=""> 
<input class="field" type="text" placeholder="Key ID" onfocus="this.placeholder=''" onblur="this.placeholder='Key ID'"> 
<input class="field" type="text" placeholder="Property Address" onfocus="this.placeholder=''" onblur="this.placeholder='Property Address'"> 
<input class="field" type="text" placeholder="Name" onfocus="this.placeholder=''" onblur="this.placeholder='Name'"> 
<input class="field" type="text" placeholder="Creditor" onfocus="this.placeholder=''" onblur="this.placeholder='Creditor'"> 
<br/><input class="button" type="submit" value="Search"> 
</form><br/> 


<h2 class="cat-title">Book Out New Key</h2> 
<form method="POST" action=""> 
<input class="field" type="text" placeholder="Key ID" onfocus="this.placeholder=''" onblur="this.placeholder='Key ID'"> 
<input class="field" type="text" placeholder="Property Address" onfocus="this.placeholder=''" onblur="this.placeholder='Property Address'"> 
<input class="field" type="text" placeholder="Name" onfocus="this.placeholder=''" onblur="this.placeholder='Name'"> 
<input class="field" type="text" placeholder="Creditor" onfocus="this.placeholder=''" onblur="this.placeholder='Creditor'"> 
<br/><input class="button" type="submit" value="Register"> 
</form> 

</div> 

<div class="results"> 
<h2 class="cat-title-right">Results</h2> 
<?php 
    //Make connection 
     mysql_connect('localhost', 'access', 'AR51Bigwater'); 
    //Select DB 
     mysql_select_db('keytracker') 

    $sql="SELECT * FROM keys"; 
    $records = mysql_query($sql); 
    //Display Data 

?> 
<table cellpadding="1" cellspacing="1"> 
<tr> 

<th>ID</th> 
<th>Name</th> 
<th>Company</th> 
<th>Out_Date</th> 
<th>Due_Date</th> 
<tr> 

<?php 
while ($keys=mysql_fetch_assoc($records)){ 
    echo "<tr>"; 
    echo "<td>".$keys['ID']."</td>"; 
    echo "<td>".$keys['Name']."</td>"; 
    echo "<td>".$keys['Company']."</td>"; 
    echo "<td>".$keys['Out_Date']."</td>"; 
    echo "<td>".$keys['Due_Date']."</td>"; 
    echo "</tr>"; 
} 
?> 
</table> 
</div> 

這是部分,其中該錯誤發生按錯誤:

<?php 
    //Make connection 
     mysql_connect('localhost', 'access', 'AR51Bigwater'); 
    //Select DB 
     mysql_select_db('keytracker') 

    $sql="SELECT * FROM keys"; 
    $records = mysql_query($sql); 
    //Display Data 

?> 
+2

你在上一行缺少一個分號 –

回答

0

該錯誤明確指出語法錯誤您錯過了36行分號,如@HoboSapiens所述。您可以使用MySQLi/PDO_MySQL,而不是mysql。整個ext/mysql PHP擴展從PHP v5.5.0開始正式被棄用,並且將來會被刪除。

您可以從here開始踢球。

<?php 
    //Make connection 
    $connection = mysqli_connect('localhost', 'access', 'AR51Bigwater','keytracker'); 

    $sql="SELECT * FROM keys"; 
    $records = mysqli_query($connection,$sql); 
    //Display Data 

?> 
0
<?php 
//Make connection 
    mysql_connect('localhost', 'access', 'AR51Bigwater'); 
//Select DB 
    mysql_select_db('keytracker'); 

$sql="SELECT * FROM keys"; 
$records = mysql_query($sql); 
//Display Data 

>

因爲syntex錯誤在mysql_select_db('keytracker')中缺少分號,所以上面的代碼放在您的代碼中;