mysql - PHP Getting Things Out Of Database -


i'm bad @ php, , need provide answer me because teacher worthless , i'm willing learn here.

simply, have upload form user can upload picture of house, , information on price , not.

i using xampp , phpmyadmin. have simple database table ready details. when upload house, information shown in database fine.

the problem is, getting information /out/ of database. keep getting error saying:

warning: mysqli_fetch_assoc() expects parameter 1 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 fix this, guys, because said, teacher literally taught nothing.

essentially, 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 sale</p>             <p>deanfield avenue, henley-on-thames</p>             <p>set in heart of henley-on-thames , short walk henley train station available , spacious 3 bedroom apartment. offered market no onward chain property benefits off road parking.</p>         </div>         <div class="housepost">             <img src="img/houses/house_02.jpg">             <h2>£475,000</h2>             <p>2 bedroom detached bungalow sale</p>             <p>fair mile, henley-on-thames</p>             <p>set in heart of town centre in quiet backwater delightful single storey detached home available , presented.</p>         </div>         <div class="housepost">             <img src="img/houses/house_03.jpg">             <h2>£600,000</h2>             <p>3 bedroom cottage sale</p>             <p>remenham row, henley-on-thames</p>             <p>the english courtyard association , beechcroft trust - synonymous best in retirement housing since 1980s. extremely attractive three-bedroom cottage landscaped riverside gardens in 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 * $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 3 houses hard coded in html, forget now. it's php concerned with. line 107 line reads:

while ( $row = mysqli_fetch_assoc($result) ) { 

the answer super simple, , duplicate, need help. reading other answers doesn't me because bad @ php syntax. v.v

schlaus' answer correct date. ran code, values machine respects , query works fine. error must in db_const.php file, values accessing database being allocated.

it not problem line stated in other 2 answers.

the following code should trick:

$servername="localhost"; $username="root"; $password=""; $dbname="content_management";  $tbl_name="houses";  // require_once("db_const.php"); $mysqli = new mysqli($servername, $username, $password, $dbname); // check connection if ($mysqli->connect_errno) {     echo "<p>mysql error no {$mysqli->connect_errno} : {$mysqli->connect_error}</p>";     exit(); }  $sql = "select * $tbl_name"; if (!$result = $mysqli->query($sql)) {     echo "error is: " . $mysqli->error; } else {     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); 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -