title: getting string from MYSQL and using it in Select stament
body: <p>I am trying to get a string from the database and use it in the Select statement . </p>
  
  <pre><code>$netpay1="netpay";
  $tbp="Paye_deductions";
  $tbq="Extra_deductions";
  
  // Connect to server and select databse.
  $conn = mysqli_connect("$host", "$username", "$password")or die("cannot connect"); 
  mysqli_select_db($conn,"$db_name")or die("cannot select DB");
  
  // Construct our join query
  // sending query
  </code></pre>
  
  <p>The code belowe fetches the string from MYSQL database</p>
  
  <pre><code>$rql = "Select * FROM $netpay1 WHERE Employee_Number = '$user1'";
  
  
  
  // output data of each row
  $result1 = mysqli_query($conn, $rql);
  $row2 = mysqli_fetch_array($result1, MYSQLI_BOTH);
  $Tax1 = $row2["Taxable_Deduction"];
  $non = $row2["non_tax_deduction"];
  </code></pre>
  
  <p>After fetching the string i want to use it to Select the items in the string  but it says error "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM Paye_deductions "
  any ideas on how this can be performed ?</p>
  
  <p>i looked in the database and this is how the string is saved "Company_Car,Housing_Allowance".</p>
  
  <pre><code>$result6 =  "SELECT $tax1 FROM $tbp WHERE Employee_Number='$user1' AND Month='$months1' AND Year='$years1'";
  
  $result55 = mysqli_query($conn, $result6);
  $row55 = mysqli_fetch_assoc($result55, MYSQLI_BOTH);
  $sum = array_sum($row55);
  
  if (!$result55) {
      die('Invalid query: ' . mysqli_error($conn));
  }
  
  echo $sum;
  echo $Tax1;
  </code></pre>