I'm really bad at PHP, and I just need someone to provide an answer for me because my teacher is worthless and I'm willing to learn from anyone here.
Simply, I have an upload form where the user can upload a picture of a house, and information on its price and what not.
I am using XAMPP and PHPMYADMIN. I have a simple database with a table ready for the details. When I upload the house, all the information is shown in the database fine.
The problem is, getting the information /out/ of the database. I keep getting an error saying:
Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in E:\xampp-portable-win32-5.6.3-0-VC11 (1)\xampp\htdocs\EstateAgent\houses.php on line 107 Connection failed:
I have no idea how to fix this, but I would really like some help from you guys, because like I said, my teacher literally taught us nothing.
Essentially, this is what my code looks like:
<form name="new-house-form" method="post" action="upload_house.php" enctype="multipart/form-data">
<label for="housepic">House Image: </label>
<input type="file" name="housepic" id="housepic"><br>
<label for="houseprice">House Price: </label>
<input type="text" name="houseprice" id="houseprice"><br>
<label for="housetype">House Type: </label>
<input type="text" name="housetype" id="housetype"><br>
<label for="houseloc">House Location: </label>
<input type="text" name="houseloc" id="houseloc"><br>
<label for="housedesc">House Description: </label>
<input type="text" name="housedesc" id="housedesc"><br>
<input type="submit" value="Upload">
</form>
<div id="content">
<h2>Our Houses</h2>
<div class="housepost">
<img src="img/houses/house_01.jpg">
<h2>£350,000</h2>
<p>2 bedroom detached house for sale</p>
<p>Deanfield Avenue, Henley-on-Thames</p>
<p>Set in the heart of Henley-on-Thames and just a short walk from Henley train station is this rarely available and spacious three bedroom apartment. Offered to the market with no onward chain the property benefits from off road parking.</p>
</div>
<div class="housepost">
<img src="img/houses/house_02.jpg">
<h2>£475,000</h2>
<p>2 bedroom detached bungalow for sale</p>
<p>Fair Mile, Henley-on-Thames</p>
<p>Set in the heart of the town centre in a quiet backwater this delightful single storey detached home is rarely available and well presented.</p>
</div>
<div class="housepost">
<img src="img/houses/house_03.jpg">
<h2>£600,000</h2>
<p>3 bedroom cottage for sale</p>
<p>Remenham Row, Henley-on-Thames</p>
<p>The English Courtyard Association and The Beechcroft Trust - synonymous with the very best in retirement housing since the 1980s. An extremely attractive three-bedroom cottage with landscaped riverside gardens in this much sought after location.</p>
</div>
<?php
$servername="localhost";
$username="root";
$password="";
$dbname="content_management";
$tbl_name="houses";
require_once("db_const.php");
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
# check connection
if ($mysqli->connect_errno) {
echo "<p>MySQL error no {$mysqli->connect_errno} : {$mysqli->connect_error}</p>";
exit();
}
$sql = "SELECT * FROM $tbl_name";
$result= $mysqli->query($sql);
while ( $row = mysqli_fetch_assoc($result) ) {
echo "<img src='" . $row['picture'] . "'>";
echo $row['price'];
echo $row['type'];
echo $row['location'];
echo $row['description'];
}
mysqli_close($mysqli);
?>
There are 3 houses already hard coded in their with HTML, just forget about those for now. It's the PHP I am concerned with. Line 107 is the line that reads:
while ( $row = mysqli_fetch_assoc($result) ) {
The answer is probably super simple, and this is probably a duplicate, but I just really need help. Reading other answers doesn't help me because I am really bad at PHP syntax. v.v