title: Unable to execute PHP code in mysql_query function. Code is stored inside variable as string
body: <p>Below is the code being used to generate the code to be executed inside the <code>mysql_query</code> function </p>
  
  <pre><code>for($i=1;$i&lt;=$totalcols;$i++) {
      $val_array[] = "\'\".\$data-&gt;val(\$i,$i).\"\'";
  
  }
  </code></pre>
  
  <p>the array above is then converted into string without slashes using <code>implode</code> and <code>stripslashes</code> function. </p>
  
  <pre><code>$val = stripslashes(implode(",",$val_array));
  </code></pre>
  
  <p>And all of it produces a string as follows</p>
  
  <pre><code>'".$data-&gt;val($i,1)."','".$data-&gt;val($i,2)."','".$data-&gt;val($i,3)."'
  </code></pre>
  
  <p>This is the string that I am using inside the <code>VALUES()</code> . Instead of executing the code and then inserting the values in database, the string is being inserted into the database as it is.The mysql_query function is being used as follows.</p>
  
  <pre><code>mysql_query("INSERT INTO import_excel ($val_string) VALUES($val)") or die(mysql_error());
  </code></pre>
  
  <p>Here is screenshot if data inserted into DB
  <img src="https://i.stack.imgur.com/38LFm.png" alt="enter image description here"></p>