mysqli - Failing to connect/get results from database using PHP -


i trying connect database , display information on page.

here model

<?php // model totals of wreath orders require_once("dbconnect.php");  // connect database , check errors @ $dbc = mysqli_connect(db_host, db_user, db_password, db_name);  $connection_error = $dbc->connect_error; if ($connection_error != null) {   echo "<p>error connectiong database: $connection_error</p>";   exit(); } ?> 

here code page construct string , try connect , display data on screen.

<?php require_once('model.php');  $query = "select * people where";  if  (isset ($_post['fname'])) {     $fname = $_post['fname'];     $query = $query . " fname = '" . $fname . "' and"; } if (isset ($_post['lname'])) {     $lname = $_post['lname'];     $query = $query . " lname = '" . $lname . "' and"; }  if (isset ($_post['age'])) {     $age = $_post['age'];     $query = $query . " age = '" . $age . "' and"; }  if (isset ($_post['city'])) {     $city = $_post['city'];     $query = $query . " city = '" . $city . "' and"; }  $query = rtrim($query, " and"); include('header.php'); ?> <div id="header"> <h1><strong>this information requested</h1></strong> </div> <div id="main"> <?php $results = $dbc->query($query); $row_count = $result->num_rows;  ($i = 0; $i < $row_count; $i++) :         $product = $result->fetch_assoc();     echo $product['fname'] . " | " . $product['lname'] . " | " . $product['age'] . " | " . $product['city'] . ' <br />'; endfor; ?> </div> <?php include('footer.php'); 

here error get

notice: undefined variable: result in c:\program files\wamp\www\testwebpage\model\getinformation.php on line 34  trying property of non-object in c:\program files\wamp\www\testwebpage\model\getinformation.php on line 34 

i can i'm pretty new , not sure wrong code.

you're using different variable name. should $results instead of $result.

replace them with:

$row_count = $results->num_rows; //line 34  $product = $results->fetch_assoc(); //line 37 

that should fix errors.


Comments