I had a custom detailed form and calculator built for a Wordpress site a couple years ago. We just migrated the site to a new host and I got an issue with the code. Since it was custom and coded a specific way, I got an error and had to change the database, user and password for MySQL from the old to the new. Just after I did that, I am getting a an error
Fatal error: Call to a member function free() on boolean in ...
I have not changed anything in the code at all. Only after migration did I get the errors but I changed the db info only, I am unsure why I am getting a new error?
<?php
$host='localhost';
$port=3306;
$socket='';
$user='my_user';
$password='passW0rd!';
$dbname='my_db';
$con = new mysqli($host, $user, $password, $dbname, $port, $socket) or die ('Could not connect to the database server' . mysqli_connect_error());
//echo "Connected to Database<br />";
$sql = "SELECT ID, Description FROM adv_sources WHERE WebItem = '-1' ORDER BY Description ASC";
$result = $con->query($sql);
$options = "";
echo "<label for 'adv_source'>How did you hear about Us?</label>\n";
echo "<select name='adv_source' id='adv_source' class='pure-u-22-24' required>\n";
echo "<option value=''>[Choose One Please]</option>\n";
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$id = $row["ID"];
$thing = $row["Description"];
//$options.="<option value=\"$id\">".$thing."</option>";
echo "<option value=\"$id\">" . $thing . "</option>\n";
}
}
echo "</select>";
$result->free();
$con->close();
?>
I believe the error is with $result
, but I know next to nothing about PHP. I get the problem with the function and code not returning a boolean but I have tried for a couple hours to research this and still nothing with the project due date in 8 hours (and I would like to get some sleep).