title: How can I get $_POST to work with my PDO statement?
body: <p>I can't seem to get $_POST to work with my sql query.  I have tried both mysql_query and PDO.  </p>
  
  <pre><code>$newartist = $_POST['newartist'];  // This doesn't work with PDO statement
  //$newartist = 'Hubert De Lartigue'; // This works with PDO statement!
  //$query = $DBH-&gt;prepare("SELECT * FROM artist WHERE artist =?"); // Original Method
  //$query-&gt;bindValue(1, $newartist, PDO::PARAM_STR); // Original Method
  
  $query = $DBH-&gt;prepare("SELECT * FROM artist WHERE artist = :newartist"); // Suggested Method
  //$query-&gt;bindParam(':newartist', $newartist); // Suggested method, tested
  $query-&gt;bindParam(':newartist', $newartist, PDO::PARAM_STR); // Suggested method
  $query-&gt;execute();
  //foreach ($query as $row) { // Switched to while loop so it can "fetch"
  while ($row = $query-&gt;fetch(PDO::FETCH_ASSOC)) {
      $selectedartist = '&lt;option value="'.$row['artist_id'].'" selected="selected"&gt;'.$row['artist'].'&lt;/option&gt;';
  }
  </code></pre>
  
  <p>I can however echo $_POST['newartist']; and it will correctly output the artist's name!</p>
  
  <p>The form per request (NOTE: you have to click the + to submit an artist and newartist echos properly after submitting a new artist): </p>
  
  <pre><code>&lt;div style="background: #270126; padding: 0 20px;" id="artist" &gt;
    &lt;form method="post" style="width: 100%"&gt;
     Artist: &lt;select name="artist" style="width: 200px; background: black;" class="required"&gt;
    &lt;?php 
      if(!empty($_POST['newartist'])) { 
          echo $selectedartist;
      } else {
          echo '&lt;option value="2" selected="selected"&gt;Unknown-Artist&lt;/option&gt;
               '.$theartist.'';
      } 
      ?&gt;&lt;/select&gt;&amp;nbsp;&lt;a href="#" style="width: 15px; font-size: 1.5em; display:inline;" onclick="document.getElementById('artistnew').style.display='block';document.getElementById('artworknew').style.display='none';document.getElementById('artist').style.display='none';"&gt;+&lt;/a&gt;&lt;/div&gt;
      &lt;div style="background: #270126; padding: 0 20px;" id="addnewartist" &gt;
          &lt;fieldset style="display: none;height: 35px;" id="artistnew"&gt;
              &lt;a href="https://www.google.com/search?q=art+" id="googlelink" class="updatethelink" target="_blank"&gt;Artist Name&lt;/a&gt;:       
              &lt;input name="newartist" id="newartist" style="width: 200px; display:inline;" /&gt;&amp;nbsp;Artist URL:&lt;input name="artist_url" value="http://" /&gt;
              &lt;input type="submit" value="Submit New Artist" name="addartist" class="secondaryAction" style="display:inline;" /&gt;
          &lt;/fieldset&gt;
      &lt;/div&gt;
      &lt;fieldset id="artworknew" style="width: 100%;"&gt;
      &lt;div style="background: #270126; padding: 0 20px;"&gt;
          Artwork Name: &lt;input name="name" id="name" style="width: 300px;" /&gt;     
      &lt;/div&gt;
      &lt;div style="background: #270126; padding: 0 20px;"&gt; 
        File Name: &lt;input name="file" id="file" style="width: 300px" value=".jpg" /&gt;&lt;br /&gt;
      &lt;/div&gt;  
      &lt;div style="background: #270126; padding: 0 20px; height: 35px;"&gt; 
          Folder: &lt;select name="folder" style="width: 200px; background: black;"&gt;
     &lt;option value="16"&gt;digitalart2&lt;/option&gt;
     &lt;?=$thefolder;?&gt;&lt;/select&gt;&amp;nbsp;
      &lt;input name="disabled" type="checkbox" value="1" /&gt;Disable
        &lt;input name="dt1" type="hidden" value="&lt;?=date("Y-m-d H:i:s");?&gt;"&gt;
      &lt;/div&gt;
      &lt;div align="center"&gt;
        &lt;input type="submit" value="Submit Artwork" name="addartwork" class="primaryAction" /&gt;
      &lt;/div&gt;&lt;/fieldset&gt;
    &lt;/form&gt;
  &lt;/div&gt;
  &lt;?php
  if ($_POST['addartist']) {
        mysql_query("INSERT INTO `artist` ( `artist_id` , `artist`, `artist_url`)
  VALUES (NULL , '".$_POST['newartist']. "', '".$_POST['artist_url']. "');") or die(mysql_error());
        //echo '&lt;meta http-equiv="refresh" content="0;url=?form=addart"&gt;';
        }
  
    if ($_POST['addartwork']) {
  //  list($subcategory, $subcategory_id, $type, $link, $width, $height) = split(":", $_POST['subcategory']);
  //  list($genre, $genre_id) = split(":", $_POST['genre']);
        mysql_query("INSERT INTO `artwork` (`id`, `name`, `artist_id`, `file`, `folder_id`, `dt1`, `approved`, `disabled`)
  
  VALUES (NULL ,  
  '".sql_inj_str($_POST['name'])."', 
  '".sql_inj_str($_POST['artist'])."', 
  '".sql_inj_str(htmlentities($_POST['file']))."',
  '".sql_inj_str($_POST['folder'])."',  
  '".sql_inj_str($_POST['dt1'])."', 
  '1', 
  '".sql_inj_str($_POST['disabled'])."');
  ") or die(mysql_error());
  
  //$qu=mysql_query("SELECT LAST_INSERT_ID() INTO @artwork;");
  
        echo '&lt;div align="center" style="margin-top: 25px;"&gt;..::[&amp;nbsp;&lt;a href="/art/'.mysql_insert_id().'" target="_blank" title="Preview Artwork"&gt;Artwork Submitted!&lt;/a&gt;&amp;nbsp;]::..&lt;/div&gt;';
    }
  include ('footer.php'); 
  ?&gt;
  </code></pre>