Reputation: 1
I have been coding a webform for facilities that when you select a facility it should bring up the relevant carpark i.e the one closest to it. I know my $result
is wrong just dont know how to fix it:
$servername = 'servername';
$username = 'username';
$password = 'password';
$SQL = mysql_connect($servername, $username, $password);
$queryNumber = $_GET['query'];
switch ($queryNumber) {
case "q1":
echo "<p>Query 1</p>";
$_GET['facility'];
echo "<p id='sql'>".$SQL."</p>";
echo "<table>";
echo " <th>Carpark</th>";
$result = "SELECT nearbyfacilities, campus FROM CarPark"; // names of columns in my database
while ( $db_field = mysql_fetch_assoc($result) ) {
echo "<tr><td>" . $db_field['carpark'] . "</tr></td>";
}
?>
Any ideas?
Upvotes: 0
Views: 37
Reputation: 3002
You don't query anywhere the DB. You need to execute mysqli_query()
with the db handler and the query string. That line is missing from your code. It should be like this:
$query = "SELECT nearbyfacilities, campus FROM CarPark"; // names of columns in my database
$result = mysqli_query($SQL, $query);
while ( $db_field = mysqli_fetch_assoc($result) ) { ... }
Also change all mysql_*
to mysqli_*
Upvotes: 1