mysql - Catchable fatal error: Object of class mysqli_result could not be converted to string in C:\wamp\www\well01\GapReport\gap_analysis.php on line 31 -


i keep receiving "catchable fatal error: object of class mysqli_result not converted string in c:\wamp\www\well01\gapreport\gap_analysis.php on line 31" error , life of me can't see why fetch_assoc not working. can see wrong code? i'm noob please forgive faux pas feel free point them out can improve result.

<!doctype html>  <html>     <head>     <meta http-equiv="content-type" content="text/html; charset=utf-8">     <title>gap analysis report</title> </head> <body>     gap analysis of <?php echo htmlentities($_get["project"])."<br/>";?> </body> </html>  <?php  /* create database connection */ include 'database.php';   /* set variables */ $project = mysqli_real_escape_string($dbcon, htmlentities ($_get["project"]));  /* match conditions ensure items same project_id retrieved */ $project_id = mysqli_query($dbcon, "select id well_projects well_projects.name = '$project'");     if (!$project_id) {     echo 'no project id can found name: ' . mysqli_error($dbcon); exit(); } /* grab milestones (well features) , status according gap analysis */ $query1 = mysqli_query($dbcon, "select well_project_milestones.name, well_project_messages.title, well_project_messages.text, well_project_milestones inner join well_project_messages     on well_project_milestones.project_id = well_project_messages.project_id     well_project_milestones.project_id = '$project_id'");     if (!$query1) {     echo 'there error sql: ' . mysqli_error($dbcon); exit(); }  if ($query1->num_rows > 0) { while ($row = $query1->fetch_assoc()) {     echo "<br> feature compliance: ". $row['well_projects_milestones.name']. " " . $row['well_project_messages.title']. " " . $row['well_project_messages.text'] . "<br>"; } } else {     echo "0 results"; }   $dbcon->close(); 

mysqli_query returns mysqli_result object ($query1) queries (which can't cast bool).

see: http://php.net/manual/en/mysqli.query.php

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

if checking query failure use

if ($query1 === false) { //strict type comparison 

instead of

if (!$query1) { //inferred type comparison try cast var. 

if want result set after query succeeds need $query1->fetch_object(); or such.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -