-2

I am trying to display data from a mysql data in a html data and have watched videos and followed them changing only what is necessary like table names DB names etc. I keep getting this error?

Parse error: syntax error, unexpected '$sql' (T_VARIABLE) in C:\xampp\htdocs\keytracker\keytracker.php on line 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>

This is the section where the error occurs as per the error:

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

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

?>
Luke12954
  • 3
  • 1

2 Answers2

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

?>

Above code is put in your code because of the syntex error is semicolon missing in mysql_select_db('keytracker');

vishuB
  • 4,173
  • 5
  • 31
  • 49
0

The error clearly states syntax error you missed the semicolon in line 36 as said by @HoboSapiens .

Note: You should use MySQLi / PDO_MySQL, instead of mysql. The entire ext/mysql PHP extension is officially deprecated as of PHP v5.5.0 and will be removed in the future.

You could kick start from here.

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

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

?>
Abey
  • 1,408
  • 11
  • 26