title: Rewrite SQL Select to use $wpdb->prepare
body: <p>I'm trying to rewrite an SQL select query to use the <code>$wpdb-&gt;prepare</code> function. My original SQL query looks like this and works fine.</p>
  
  <pre><code>function hfwp_SaveFormData($formData, $userID, $today, $dbTable) {
     global $wpdb;
  
     $wpdb-&gt;show_errors();
     $query = "SELECT UserID FROM $dbTable WHERE Date = '$today' AND UserID = '$userID'";
     $wpdb-&gt;get_results( $query );
     $count = $wpdb-&gt;num_rows;
  
     if ($count &gt; 0) {
        $wpdb-&gt;update($dbTable, array('Distance' =&gt; $formData), array('Date' =&gt; $today, 'UserID' =&gt; $userID));
     }else{
        $wpdb-&gt;insert($dbTable, array('UserID' =&gt; $userID, 'Date' =&gt; $today, 'Distance' =&gt; $formData));
     }
  }
  </code></pre>
  
  <p>I then tried to rewrite the <code>SELECT</code> statement to use <code>$wpdb-&gt;prepare</code>:</p>
  
  <pre><code>$wpdb-&gt;get_results( $wpdb-&gt;prepare("SELECT UserID FROM %s WHERE Date = %s AND UserID = %d", $dbTable, $today, $userID ) );
  </code></pre>
  
  <p>But it gives an error in the log but not enough to give me a hint on what is wrong.</p>
  
  <p>I also tried another version of the <code>$wpdb-&gt;prepare</code>:</p>
  
  <pre><code>$query = "SELECT UserID FROM %s WHERE Date = %s AND UserID = %d";
  $prepared = $wpdb-&gt;prepare( $query , $dbTable, $today, $userID );
  $wpdb-&gt;get_results( $prepared );
  </code></pre>