Insert into MySQL using variable for columns through PHP
<p>On the front end of my PHP, I want the user to decided what field to insert into among multiple fields.  I can do that with multiple 'if' statements like I have below, but that makes for a long code.  Can I use a variable for the field, i.e Song_id, Album_id?  I've tried doing something like "Insert into Song(?) values (?)" but that doesn't seem to work.</p>

<pre><code>    case "insert":
    if ($table=="Song"){
        if($field=="Song_id"){
            $stmt = $db-&gt;prepare("INSERT into Song(Song_id) values (?)");
            $stmt-&gt;bindValue(1, $_POST['value'], PDO::PARAM_INT);
            $stmt-&gt;execute();
            echo "done";}
        break;}
    if ($table=="Song"){
        if($field=="Alubm_id"){
            $stmt = $db-&gt;prepare("INSERT into Song(Album_id) values (?)");
            $stmt-&gt;bindValue(1, $_POST['value'], PDO::PARAM_INT);
            $stmt-&gt;execute();
            echo "done";}
        break;}
</code></pre>

<p>etc, etc, etc.</p>

<p>Thanks!</p>