EDIT: SOLVED. Thanks to the guys in the comments who recommended turning PHP error messages on, showed me exactly where things were going wrong. For those that are curious, it was as simple as this: two function calls had "mysql_" instead of "mysqli_". Also thanks to the user that pointed out that prepared SQL queries must use ->execute() instead of mysqli_query().
I'm working on a community bulletin board. I've gotten it to a point where the page for posting a listing works and submits it to the database, but when I try to search for the listings I'm having some trouble with the SQL query. Here's the code that I have:
<?php
if(isset($_GET['submit'])){
$location = $_GET['location'];
echo "Looking for listings in: " . $location;
echo "<br />";
require_once('mysqli_connect.php');
$query = "
SELECT email_address
, phone_number
, date
, listing_content
FROM listings
WHERE location='?'
";
echo $query;
$stmt = mysqli_prepare($dbc, $query);
mysqli_stmt_bind_param($stmt, "s", $location);
$results = mysqli_query($stmt);
$numListings = mysql_num_rows($results);
echo $numListings . " listing(s) found";
echo "<hr>";
if ($numListings == 0){
echo "Feel free to press the button above to post the first listing in " .
$location;
} else {
while($row = mysql_fetch_array($results)){
echo "Location: " . $location;
echo "<br />";
echo "Date: " . $row[date];
echo "<br />";
echo "Email address: " . $row[email_address];
echo "<br />";
if($row[phone_number] != NULL){
echo "Phone number: " . $row[phone_number];
echo "<br />";
}
echo $row[listing_content];
echo "<br />";
echo "<hr>";
}
}
mysqli_stmt_close($stmt);
mysqli_close($dbc);
}
?>
And this is the output I'm getting, where everything below the button "Make new post" is generated by the PHP:
It looks like it's crashing, at some point after the line echo $query;
because it prints that out but it doesn't print some of the other statements after that. Either it's crashing or the SQL query is somehow messing up without crashing it or throwing an error.
This is what the database looks like: