Hello all, like the title says, I have written a prepared statement for a database search form. I believe I am incorrectly trying to display the results of this MySQL query. I’m a PHP newb and most of what you see below has been pieced together from various man pages and stack overflow posts. Can anyone identify why nothing is being displayed (including the "Total Results: " echo statement)? Thanks
[php]<?php
ini_set(‘display_errors’,1);
require_once ‘dbinfo.php’;
session_start();
// Save input data from HTML form
$employer_title = $_POST['employer_title'];
$industry_type = $_POST['industry_type'];
$region = $_POST['region'];
// Create connection
// TODO: What are the correct fields for server, user, pw?--------->//I made a dbinfo.php and included here and set you up! JR
$db = new mysqli($dbSite, $userName, $dbPassword, $dbName);
// Check connection
if ($db->connect_errno) {
echo "Failed to connect to database: (" . $db->connect_errno . ") " . $db->connect_error;
}
// Prepared statement step #1: Prepare
if (!($statement = $db->prepare("SELECT `name`, 'industry', 'region', 'website', 'phone', 'hq' FROM `employer` WHERE `name` = ? AND 'industry' = ? AND 'region' = ?"))) {
echo "Prepare failed: (" . $db->errno . ") " . $db->error;
}
// Prepared statement step #2: Bind parameters
if (!$statement->bind_param('sss', $employer_title, $industry_type, $region)) {
echo "Binding parameters failed: (" . $statement->errno . ") " . $statement->error;
}
// Prepared statement step #3: Execute the prepared statement
if (!$statement->execute()) {
echo "Execute failed: (" . $statement->errno . ") " . $statement->error;
}else{
echo 'Total results: ' . $statement->num_rows;
// TODO: Update this with whatever fields we want displayed
while($row = $statement->mysqli_stmt::fetch_result()){
echo $row['name'] . '<br />';
}
$statement->free();
}
$db->close();
?>[/php]