title: Insert values to mysql from select query
body: <p>I have a php results page which gets values from submited php form like</p>
  
  <pre><code>$sales = mysqli_real_escape_string($link, (int)$_POST['sales']);
  </code></pre>
  
  <p>I have an insert query </p>
  
  <pre><code>$sql = "INSERT INTO daily (date, sales) VALUES (CURRENT_TIMESTAMP, '$sales')";
  if(mysqli_query($link, $sql)){
      "Records added successfully.";
  } else{
      echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
  }
  </code></pre>
  
  <p>Now i want to add an extra field to db which will be based on a new select query</p>
  
  <pre><code>$query = "SELECT SUM(sales) FROM daily WHERE date BETWEEN '2017-01-01' AND '2017-01-31'";
  </code></pre>
  
  <p>I've tried to add it to insert sql with no result</p>
  
  <pre><code>$sql = "INSERT INTO daily (date, sales, total_sales) VALUES (CURRENT_TIMESTAMP, '$sales', '$query')";
  if(mysqli_query($link, $sql)){
      "Records added successfully.";
  } else{
      echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
  }
  </code></pre>