title: INSERT INTO..SELECT and store result
body: <p>I'm wondering if it is possible to use an <strong>INSERT INTO...SELECT</strong> to insert <strong>and</strong> to store and bind the result from the select query. </p>
  
  <p><strong>Working INSERT INTO..SELECT (not storing the result):</strong> </p>
  
  <pre><code>$query = "INSERT INTO reportmessage (header, sentdate, senttime, ip)
            VALUES ((SELECT header
                     FROM conversation 
                     WHERE id = ?), ?, ?, ?)";
  
            $stmt = $dbconn-&gt;prepare($query);
            $stmt-&gt;bind_param('ssss', $convid, $date, $time, $ip);
            if ($stmt-&gt;execute() == false) {
              $flag = false;
            }
            $stmt-&gt;close();
  </code></pre>
  
  <p><strong>What I want to accomplish if possible (not working, throws an <em>Call to a member function bind_param() on boolean error</em>):</strong></p>
  
  <pre><code>$query = "INSERT INTO reportmessage (header, sentdate, senttime, ip)
            VALUES ((SELECT c.header, c.useroneFK, c.usertwoFK
                     FROM conversation c
                     WHERE c.id = ?), ?, ?, ?)";
  
            $stmt = $dbconn-&gt;prepare($query);
            $stmt-&gt;bind_param('ssss', $convid, $date, $time, $ip);
            if ($stmt-&gt;execute() == false) {
              $flag = false;
            }
            $stmt-&gt;bind_result($header, $useroneFK, $usertwoFK);
            $stmt-&gt;fetch();
            $stmt-&gt;close();
  </code></pre>