title: INSERT INTO table (user_2) VALUES (?) WHERE user_1 IS NOT NULL
body: <p>After post request i need to:</p>
  <ol>
  <li>Check if u_1 exists on table and if it is in table insert u_2 where u_1 in not null</li>
  <li>If u_1 is not exists insert u_1</li>
  </ol>
  <p>Here is my <strong>PHP</strong> code</p>
  <pre><code>if ( isset( $_POST[&quot;cards&quot;],$_POST[&quot;user&quot;],$_POST[&quot;cardvalues&quot;],$_POST[&quot;tablekey&quot;] ) ) {
  
      $cards = $_POST[&quot;cards&quot;];
      $user = $_POST[&quot;user&quot;];
      $cardvalues = $_POST[&quot;cardvalues&quot;];
      $tablekey = $_POST[&quot;tablekey&quot;];
  
      $checkIfNull = &quot;SELECT u_1 FROM tables&quot;;
      $insertIntoU_2 = &quot;INSERT INTO tables (u_2) VALUES (?) WHERE u_1 IS NOT NULL&quot;;
      $insertIntoU_1 = &quot;INSERT INTO tables (u_1,all_cards,card_value,table_key) VALUES (?,?,?,?)&quot;;
  
      if ($stmt = $conn-&gt;prepare($checkIfNull)) {
          if ($stmt-&gt;execute()) {
              $result = $stmt-&gt;get_result();
              if ($result-&gt;num_rows &gt; 0) {
                  if ($stmt = $conn-&gt;prepare($insertIntoU_2)) {
                      $stmt-&gt;bind_param(&quot;s&quot;,$user);
                      if ($stmt-&gt;execute()) {
                          echo &quot;user 2 is in table&quot;;
                      }
                  }
              }else{
                  if ($stmt = $conn-&gt;prepare($insertIntoU_1)) {
                      $stmt-&gt;bind_param(&quot;ssss&quot;,$user,$cards,$cardvalues,$tablekey);
                      if ($stmt-&gt;execute()) {
                          echo &quot;user 1 is in table&quot;;
                      }
                  }
              }
          }
      }
  </code></pre>