php - mysqli Parameter Error - DB Connection Working Fine? -


i adding value column in 1 of tables. goal have column data show on page through table. however, when add in code (to loop through table , show data), error:

<?php  while($row = mysqli_fetch_array($result)) {     $customer_name = $row['customername'];   echo "<tr>         <td>$customer_name</td>      </tr>";      } // end while loop   ?> 

error

warning: mysqli_fetch_array() expects parameter 1 mysqli_result, boolean given in xxx on line 35

i have done research on error, i've seen responses saying database connection incorrect. however, checked database , value indeed being entered in table should, there no issue connecting or querying database.

i have commented out above code, , html shows fine well. have isolated issue being while/array code above. error appears when segment of code added script.

please let me know if find insights in issue error, , table not displaying. i've used same type of code similar script , have never set parameter, , it's worked fine.

here full code if needed:

<?php require_once("./includes/database_connection.php");  error_reporting(e_all); ini_set('display_errors', 1);  $query = "insert customers(customername) values('ikb')";  $result = mysqli_query($dbc, $query)     or die ('error querying databse'); ?>  <!doctype html> <html> <head>     <meta charset='utf-8'>     <title>home</title>     <link type="text/css" rel="stylesheet" href="classic_cars.css" /> </head>  <body>     <?php         require_once("./includes/navigation.php");     ?>      <table>         <tr>                 <td>customername</td>         </tr>     </table>          <?php      while($row = mysqli_fetch_array($result)) {         $customer_name = $row['customername'];       echo "<tr>             <td>$customer_name</td>          </tr>";          } // end while loop       ?>      <?php         mysqli_close($dbc);         require_once("./includes/footer.php");     ?>       </body> </html> 

here db connection:

<?php     define('db_location', 'x');     define('db_username', 'x');     define('db_pass', 'x');     define('db_name', 'x');      $dbc = mysqli_connect(db_location, db_username, db_pass, db_name)         or die('error connecting database');  ?> 

from the manual, section on return values:

returns false on failure. successful select, show, describe or explain queries mysqli_query() return mysqli_result object. other successful queries mysqli_query() return true.

your query insert, return type boolean true or false. why $result boolean instead of mysqli_result object.

it seems that, @ least in example code, know customer name @ beginning in order insert why not save value reuse later on? otherwise if need retrieve full record database again whatever reason need new select query before doing while($row = mysqli_fetch_array($result)).


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -