0

So I am trying to connect to my database and display the Vehicles on the web page. However it is just coming up with a blank page, and not displaying anything.

Below is the code for the page I was to display the contents of vehicles on from my database

Any Ideas?

<?php
   $conn = @mysqli_connect("localhost", "root", "2401", "taylor_callaghan_wca");

$query = "SELECT * FROM vehicle";
$results = mysqli_query($conn, $query);
if(!$results) {
echo ("Query error: " . mysqli_error($conn));
}

else {
// Fetch and display the results of the select query
while ($row = mysqli_fetch_array($results)) {
echo "<p>VIN_#: $row[vin]</p>";
echo "<p>Stock Number: $row[stockno]</p>";
echo "<p>Manufacturer Number: $row[man_num] </p>";
echo "<p>Model: $row[model] </p>";
echo "<p>Colour: Id $row[col_id] </p>";
echo "<p>Year: $row[year] </p>";
echo "<p>Price: $row[price] </p>";
echo "<p>Kilometres: $row[kms] </p>";
echo "<p>Registration: $row[rego] </p>";
echo "<p>Cylinders: $row[cylinders] </p>";
echo "<p>Fuel: $row[fuel] </p>";
echo "<p>Transmission: $row[transmission] </p>";
echo "<p>Category Id: $row[cat_id] </p>";
echo "<p>Vehicle On Special: $row[special] </p>";
echo "<p>Standard Used Vehicle: $row[standardusedvehicle] </p>";
}
}

?>
Taylor
  • 29
  • 10
  • You have a rubbish password, Taylor. Either way, it's likely an error and you need to turn on `display_errors`. – Farkie Jun 07 '17 at 07:00
  • first try to verify that your webserver is up and running and catches your request. The easiest way to check is to put some echo at the beginning of your php. If that works then check the error log. – katona.abel Jun 07 '17 at 07:02
  • Single Quotes are missing. `$row` is an array. So it should be `$row['vin']` – Milan Chheda Jun 07 '17 at 07:05
  • 1
    https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display/21429652#21429652 – Nanne Jun 07 '17 at 07:17
  • @MilanChheda You don't put the quotes in the index when you're substituting inside a string, unless you also wrap it with `{}`. See example #9 in http://php.net/manual/en/language.types.string.php – Barmar Jun 07 '17 at 07:28

1 Answers1

0

It's not really an answer but I can't post this code in comment. Try addind echos to see what it does and what it doesn't:

<?php
echo '1';
$conn = @mysqli_connect("localhost", "root", "2401", "taylor_callaghan_wca");

$query = "SELECT * FROM vehicle";
$results = mysqli_query($conn, $query);
if(!$results) {
    echo '2';
    echo ("Query error: " . mysqli_error($conn));
}

else {
    echo '3';
    // Fetch and display the results of the select query
    while ($row = mysqli_fetch_array($results)) {
        echo '4';
        echo "<p>VIN_#: $row[vin]</p>";
        echo "<p>Stock Number: $row[stockno]</p>";
        echo "<p>Manufacturer Number: $row[man_num] </p>";
        echo "<p>Model: $row[model] </p>";
        echo "<p>Colour: Id $row[col_id] </p>";
        echo "<p>Year: $row[year] </p>";
        echo "<p>Price: $row[price] </p>";
        echo "<p>Kilometres: $row[kms] </p>";
        echo "<p>Registration: $row[rego] </p>";
        echo "<p>Cylinders: $row[cylinders] </p>";
        echo "<p>Fuel: $row[fuel] </p>";
        echo "<p>Transmission: $row[transmission] </p>";
        echo "<p>Category Id: $row[cat_id] </p>";
        echo "<p>Vehicle On Special: $row[special] </p>";
        echo "<p>Standard Used Vehicle: $row[standardusedvehicle] </p>";
    }
}
echo '5';
?>
NoOorZ24
  • 2,914
  • 1
  • 14
  • 33
  • Error: `$row` is an array. So it should be `$row['vin']` – Milan Chheda Jun 07 '17 at 07:07
  • I know this is not an answer to fix the problem it's just meant to show how to find out where program is stopped (if there is no errors and it is executed) and if nothing shows up then you can at least know that it's not executed – NoOorZ24 Jun 07 '17 at 07:11