title: How to get current user_id of logged in user
body: <p>I just created a php file to update a field in mysql db, my update query is where i have an issue, i want to set 'user_id' to be the user_id of the current user that is logged in so the update will go to the appropriate user. I haven't been able to get this to work. I feel its because i haven't declared the current user earlier in the code, how can i do this?</p>
  
  <p>Here is the line:</p>
  
  <pre><code>$sql = "UPDATE wp85_usermeta SET `meta_value` = `meta_value`+65000 WHERE `user_id` = user_id AND `meta_key` = 'mycred_default'"
  </code></pre>
  
  <p>Here is the full code:</p>
  
  <pre><code>&lt;?php
      $servername = "localhost";
      $username = "sparyqmr_wp324";
      $password = "(S8p3uV-2t";
      $dbname = "sparyqmr_wp324";
  
      // Create connection
      $conn = new mysqli($servername, $username, $password, $dbname);
      // Check connection
      if ($conn-&gt;connect_error) {
          die("Connection failed: " . $conn-&gt;connect_error);
      }
  
      $sql = "UPDATE wp85_usermeta SET `meta_value` = `meta_value`+65000 WHERE `user_id` = user_id AND `meta_key` = 'mycred_default'";
  
      if ($conn-&gt;query($sql) === TRUE) {
          echo "Record updated successfully";
      } else {
          echo "Error updating record: " . $conn-&gt;error;
      }
  
      $conn-&gt;close();
  ?&gt;
  </code></pre>