php - Getting fetch_object() error on a successful query -


i'm getting error:

fatal error: call member function fetch_object() on non-object in c:\.....php on line 136 

here's code:

if ($result = $mysqli->query("insert partlistlist ( p_fam , p_code , p_name, p_var , p_ver , p_lnk , p_fol , p_notes , p_status , p_op ) values ( \"".$mod_fam ."\", \"".$mod_code ."\", \"".$mod_name ."\", \"".$mod_var  ."\", 1 , \"".$mod_lnk  ."\", \"".$mod_fold ."\", \"".$mod_note     ."\", \"".$mod_stat ."\", \"".  $_session['wh_pwd_usr']."\"  ) ")); {     echo "<br>articolo creato con successo";     $created_id = $mysqli->insert_id;     if (!$result = $mysqli->query("select * partlistlist p_id = $created_id limit 1"))         echo "error";     $row = $result->fetch_object();     $p_id = $created_id;      if (!$result_clonepart = $mysqli->query("select * partlist k_pid = $old_p_id"))     {         echo "error";     }     else     {         if ($result_clonepart->num_rows > 0)         {             while ($row_clonepart = $result_clonepart->fetch_object())             {                 if (!$result_clonepart = $mysqli->query("insert partlist ( k_ref ,k_pid ,k_iid ,k_qty ,k_subpid, k_stat ) values ( \"".$row_clonepart->k_ref      ."\" ,\"". $p_id    ."\" ,\"".$row_clonepart->k_iid     ."\" ,\"".$row_clonepart->k_qty     ."\" ,\"".$row_clonepart->k_subpid   ."\" ,\"".$row_clonepart->k_stat       ."\")"))                     echo "error";             }           }     } } 

line 136 is:

while ($row_clonepart = $result_clonepart->fetch_object()) 

how can $result_clonepart not object, if the num_rows check good?

in while loop reassigning $result_clonepart (what don't want do). if query fails script stop fatal error.

use different variable name (if don't want use same variable name) or break loop on failure (if reassigning intentionally)

while ($row_clonepart = $result_clonepart->fetch_object()) {   //     vvvvvvvvvvv     here reassignment   if (!$result_clonepart = $mysqli->query("insert partlist ( k_ref ,k_pid ,k_iid ,k_qty ,k_subpid, k_stat ) values ( \"".$row_clonepart->k_ref      ."\" ,\"". $p_id    ."\" ,\"".$row_clonepart->k_iid     ."\" ,\"".$row_clonepart->k_qty     ."\" ,\"".$row_clonepart->k_subpid   ."\" ,\"".$row_clonepart->k_stat       ."\")"))       echo "error";       //you insert break statement if reassigning variable intentionally } 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -