title: Bind textfield value to array and put in database
body: <p>I'm making a simple private messing system. When a user sends a message he/she has to fill in three fields: 'to', 'subject' and 'message'. In the 'to' field a user can enter a username to send his/hers message to. Then, using mySql (phpmyadmin), I try to fetch the corresponding user_id from the users table. 
  for example, user_id '1' has user_name 'testing'. When a user types in 'testing' in the 'to' field, my code searches in the users table for the user with the user_name 'testing' and takes the corresponding user_id.
  After taking the user_id it puts the user_id in the conversations_members table. </p>
  
  <p>My problem is that the code DOES take the correct user_id (I checked this by printing the array), but it doesn't put the correct user_id in the table. It always puts 0.</p>
  
  <p>See code below, here I add the user_id to the array $user_ids</p>
  
  <pre><code>   else if(!empty($_POST['to'])){
          $stmt = $db-&gt;prepare("SELECT user_id FROM user WHERE user_name = :user_name");
          $stmt-&gt;bindValue(':user_name', $_POST['to'], PDO::PARAM_STR);
          $stmt-&gt;execute();
  
          $result = $stmt-&gt;fetch(PDO::FETCH_ASSOC);
          if ($result) {
              $user_ids['user_id'] = $result['user_id'];
          }
  </code></pre>
  
  <p>See code below, here I try to add the user_id to the table</p>
  
  <pre><code>$sql4 = $db-&gt;prepare("INSERT INTO conversations_members
                      (conversation_id, user_id, conversation_last_view, conversation_deleted) 
                      VALUES (:conid, :usid, :clv, :condel)");
  $sql4-&gt;execute(array(
      "conid" =&gt; "{$conversation_id}",
      "usid" =&gt; "{$user_ids[0]['user_id']}",
      "clv" =&gt; "0",
      "condel" =&gt; "0"
      ));
  </code></pre>
  
  <p>I really hope anyone can help, I've been struggling for a few hours now :(
  Thanks in advance!!</p>