title: inserting a blank row before inserting the correct one mysql
body: <p>I am working on a angular5 / php backend project, and I am having an issue where I have a registration form, when the user registers it creates a blank row (empty strings values) in the user table followed by the correct row (colomn values).</p>
  
  <p>The following is my form: </p>
  
  <pre><code>&lt;form *ngIf="!isLogin" (submit)="onRegisterSubmit()" [formGroup]="registerForm"&gt;
                              &lt;div class="form-control"&gt;
                                  &lt;input type="text" name="firstname" id="firstname" class="form-control" placeholder="Firstname" formControlName="fn"&gt;
                                  &lt;div class="throw_error" *ngIf="registerForm.controls.fn.invalid &amp;&amp; registerForm.controls.fn.touched"&gt;
                                      &lt;div *ngIf="registerForm.controls.fn.errors?.required"&gt;This field is required&lt;/div&gt;
                                      &lt;div *ngIf="registerForm.controls.fn.errors?.minlength"&gt;This field must be at least 3 characters&lt;/div&gt;
                                      &lt;div *ngIf="registerForm.controls.fn.errors?.maxlength"&gt;This field must have at most 10 characters&lt;/div&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                              &lt;div class="form-control"&gt;
                                  &lt;input type="text" name="lastname" id="lastname" class="form-control" placeholder="Lastname" formControlName="ln"&gt;
                                  &lt;div class="throw_error" *ngIf="registerForm.controls.ln.invalid &amp;&amp; registerForm.controls.ln.touched"&gt;
                                      &lt;div *ngIf="registerForm.controls.ln.errors?.required"&gt;This field is required&lt;/div&gt;
                                      &lt;div *ngIf="registerForm.controls.ln.errors?.minlength"&gt;This field must be at least 3 characters&lt;/div&gt;
                                      &lt;div *ngIf="registerForm.controls.ln.errors?.maxlength"&gt;This field must have at most 10 characters&lt;/div&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                              &lt;div class="form-control"&gt;
                                  &lt;input type="email" name="email2" id="email2" class="form-control" placeholder="Email Address" formControlName="email2"&gt;
                                  &lt;div class="throw_error" *ngIf="registerForm.controls.email2.invalid &amp;&amp; registerForm.controls.email2.touched"&gt;
                                      &lt;div *ngIf="registerForm.controls.email2.errors?.required"&gt;This field is required&lt;/div&gt;
                                      &lt;div *ngIf="registerForm.controls.email2.errors?.email &amp;&amp; !registerForm.controls.email2.errors?.required"&gt;This email is invalid&lt;/div&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                              &lt;div class="form-control"&gt;
                                  &lt;input type="password" name="password2" id="password2" class="form-control" placeholder="Password" formControlName="password2"&gt;
                                  &lt;div class="throw_error" *ngIf="registerForm.controls.password2.invalid &amp;&amp; registerForm.controls.password2.touched"&gt;
                                      &lt;div *ngIf="registerForm.controls.password2.errors?.required"&gt;This field is required&lt;/div&gt;
                                      &lt;div *ngIf="registerForm.controls.password2.errors?.minlength"&gt;This field must be at least 6 characters&lt;/div&gt;
                                      &lt;div *ngIf="registerForm.controls.password2.errors?.maxlength"&gt;This field must have at most 15 characters&lt;/div&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                              &lt;div class="form-control"&gt;
                                  &lt;input type="password" name="confirmPassword" id="confirm-password" class="form-control" placeholder="Confirm Password" formControlName="confPass"&gt;
                                  &lt;div class="throw_error" *ngIf="registerForm.controls.confPass.touched &amp;&amp; registerForm.controls.confPass.errors?.MatchPassword"&gt;Passwords do not match&lt;/div&gt;
                              &lt;/div&gt;
                              &lt;div class="form-control"&gt;
                                  &lt;div class="row"&gt;
                                      &lt;div class="col-sm-3"&gt;&lt;/div&gt;
                                      &lt;div class="col-sm-6"&gt;
                                          &lt;input type="submit" name="register-submit" id="register-submit" [disabled]="registerForm.invalid" 
                                                  class="form-control btn btn-register" value="Submit"&gt;
                                          &lt;span class="throw_error" id="success"&gt;{{resultReg}}&lt;/span&gt;
                                      &lt;/div&gt;
                                      &lt;div class="col-sm-3"&gt;&lt;/div&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/form&gt;
  </code></pre>
  
  <p>This is my typescript code for the registration function: </p>
  
  <pre><code>onRegisterSubmit() {
  const regFormValue = this.registerForm.value;
  
  this.http.post("http://localhost/ProjetErgonomie/RegUser.php", regFormValue)
    .subscribe(data =&gt; {
      this.receivedData = data;
      if (this.receivedData.success) {
        this.resultReg = "User added successfully";
      } else {
        this.resultReg = this.receivedData.errors;
      }
    }, (error) =&gt; {
      console.log(error);
    });
   }
  </code></pre>
  
  <p>And this is my RegUser.php page:</p>
  
  <pre><code>&lt;?php
  header("Access-Control-Allow-Headers: Content-Type");
  header("Access-Control-Allow-Origin: *");
  
  require_once ('./DBConnect.php');
  $conn = mysqli_connect($servername, $username, $password, $db ,$port);
  
  $regUserData = json_decode(file_get_contents("php://input"),true);
  $fn = $regUserData['fn'];
  $ln = $regUserData['ln'];
  $email = $regUserData['email2'];
  $pass = $regUserData['password2'];
  $confPass = $regUserData['confPass'];  
  
  $errorsReg = "";
  $dataReg=array();
  
  if($fn === '' || $ln === '' || $email === '' || $pass === '' || $confPass === ''){
      $errorsReg = 'Please fill all fields';
      $dataReg['success'] = FALSE;
  }
  
  else{
      $checkUserQuery = "select * from user where Email = '".$email."'";
      $result = $conn-&gt;query($checkUserQuery);
      if(mysqli_num_rows($result)&gt;0){
          $errorsReg = 'User already exists';
          $dataReg['success'] = FALSE;
      }
      else{
          $sql = "INSERT INTO user (Firstname, Lastname, Email, Password, NewUser)
              VALUES ('".$fn."','".$ln."','".$email."','".md5($pass)."',1)";
          mysqli_query($conn,$sql);
          $dataReg['success'] = TRUE;
      }
  }
  $dataReg['errors']=$errorsReg;
  echo json_encode($dataReg);
  </code></pre>
  
  <p>can you please tell me why am I getting a blank row before having the correct row inserted?</p>