title: How to save result of a query in variable?
body: <p>I'm trying to save result of a MYSQL query in variable. I know that results save as an array but I don't know how to assign result to variable.
  I could echo result but I couldn't assign it to variable.</p>
  
  <p>here is my code with error:</p>
  
  <pre><code>require('db.php');
  $id =$_REQUEST['id'];
  $name ="SELECT name FROM table2 WHERE id='".$id."'";
  $name_result = $con-&gt;query($name);
  while($row = $name_result-&gt;fetch_assoc()) {
          $name=$row['name'];
      }
  $ins_query=" insert into table1 (`id`,`name`) values ('$id','$name')";
  $stat=mysqli_query($con,$ins_query) or die(" error".mysql_error());
  </code></pre>
  
  <p>Id gets from user as html input field and will save in table1.
  Name exists in table2 and I want to select it where id in table1 is equals with id in table2 then insert it in table1.</p>