title: PHP print multiple lines of code instead of execute query and put elements in Database (registration form)
body: <p>Hy, im new on php and im trying to make a registration and login form, but he show this code when i click the submit button to submit my user informations to database:</p>
  <p>page sign-up.php:</p>
  <pre><code>&lt;?php
  require('functions/database.php');
  session_start();
  if(isset($_SESSION['user_id'])) {
   header(&quot;Location:dashboard.html&quot;);
  }
  session_destroy();
  session_start();
  ob_start();
  ?&gt;
  
  &lt;html&gt;
  [...]
  &lt;head&gt;
  [...]
  &lt;body&gt;
  &lt;form role=&quot;form text-left&quot; action=&quot;sign_up.php&quot; method=&quot;POST&quot;&gt;
      &lt;div class=&quot;mb-3&quot;&gt;
          &lt;input type=&quot;text&quot; class=&quot;form-control&quot; placeholder=&quot;First Name&quot; name=&quot;userfirstname&quot; id=&quot;userfirstname&quot;&gt;
      &lt;/div&gt;
      &lt;div class=&quot;mb-3&quot;&gt;
          &lt;input type=&quot;text&quot; class=&quot;form-control&quot; placeholder=&quot;Last Name&quot; name=&quot;userlastname&quot; id=&quot;userlastname&quot;&gt;
      &lt;/div&gt;
      &lt;div class=&quot;mb-3&quot;&gt;
          &lt;input type=&quot;text&quot; class=&quot;form-control&quot; placeholder=&quot;Nickname&quot; name=&quot;usernickname&quot; id=&quot;usernickname&quot;&gt;
  
      &lt;/div&gt;
      &lt;div class=&quot;mb-3&quot;&gt;
          &lt;input type=&quot;password&quot; class=&quot;form-control&quot; placeholder=&quot;Password&quot; name=&quot;userpass&quot; id=&quot;userpass&quot;&gt;
      &lt;/div&gt;
      &lt;div class=&quot;mb-3&quot;&gt;
          &lt;input type=&quot;password&quot; class=&quot;form-control&quot; placeholder=&quot;Confirm Password&quot; name=&quot;userpassconfirm&quot; id=&quot;userpassconfirm&quot;&gt;
      &lt;/div&gt;
      &lt;div class=&quot;mb-3&quot;&gt;
          &lt;input type=&quot;email&quot; class=&quot;form-control&quot; placeholder=&quot;Email&quot; name=&quot;useremail&quot; id=&quot;useremail&quot;&gt;
  
      &lt;/div&gt;
      &lt;div class=&quot;mb-3&quot;&gt;
          &lt;input type=&quot;text&quot; class=&quot;form-control&quot; placeholder=&quot;Hometown&quot; name=&quot;userhometown&quot; id=&quot;userhometown&quot;&gt;
      &lt;/div&gt;
      &lt;div class=&quot;text-center&quot;&gt;
          &lt;input type=&quot;submit&quot; class=&quot;btn bg-gradient-dark w-100 my-4 mb-2&quot; name=&quot;register&quot;&gt;&lt;/input&gt;
      &lt;/div&gt;
          &lt;p class=&quot;text-sm mt-3 mb-0&quot;&gt;Already have an account? &lt;a href=&quot;javascript:;&quot; class=&quot;text-dark font-weight-bolder&quot;&gt;Sign in&lt;/a&gt;&lt;/p&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/head&gt;
  &lt;/html&gt;
  </code></pre>
  <p>page sign_up.php:</p>
  <pre><code>&lt;?
  session_start();
  require_once('functions/database.php');
  
  if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  
      if (isset($_POST['register'])) {
          // Retrieve Data
          $userfirstname = $_POST['userfirstname'];
          $userlastname = $_POST['userlastname'];
          $usernickname = $_POST['usernickname'];
          $userpassword = md5($_POST['userpass']);
          $useremail = $_POST['useremail'];
          $userhometown = $_POST['userhometown'];
  
          $query = &quot;SELECT user_email, FROM users WHERE user_email=:email&quot;;
          $check = $pdo-&gt;prepare($query);
          $check-&gt;bindParam(':email', $useremail, PDO::PARAM_STR);
          $check-&gt;execute();
  
          $checkquery = $check-&gt;fetchAll(PDO::FETCH_ASSOC);
  
          if ($count($checkquery) &gt; 0) {
              $msg = &quot;User alredy registered&quot;;
  
          } else {
              // Insert Data
              $query = &quot;INSERT INTO users(user_firstname, user_lastname, user_nickname, user_password, user_email,  user_hometown) VALUES (:firstname, :lastname, :nickname, :password, :email, :hometown)&quot;;
              $check = $pdo-&gt;prepare($query);
              $check-&gt;bindParam(':firstname', $userfirstname, PDO::PARAM_STR);
              $check-&gt;bindParam(':lastname', $userlastname, PDO::PARAM_STR);
              $check-&gt;bindParam(':nickname', $usernickname, PDO::PARAM_STR);
              $check-&gt;bindParam(':password', $userpassword, PDO::PARAM_STR);
              $check-&gt;bindParam(':email', $useremail, PDO::PARAM_STR);
              $check-&gt;bindParam(':hometown', $userhometown, PDO::PARAM_STR);
              $check-&gt;execute();
  
              if ($check-&gt;rowCount() &gt; 0) {
                  $msg = &quot;success!&quot;;
  
              } else {
                  $msg =&quot;error, try again&quot;;
              }
          }
      }
  }
  
  echo $msg;
  ?&gt;
  </code></pre>
  <p>error when submit registration form:</p>
  <pre><code>prepare($query); $check-&gt;bindParam(':email', $useremail, PDO::PARAM_STR); $check &gt;execute(); $checkquery = $check-&gt;fetchAll(PDO::FETCH_ASSOC); if ($count($checkquery) &gt; 0) { $msg = &quot;Utente gia registrato&quot;; } else { // Insert Data $query = &quot;INSERT INTO users(user_firstname, user_lastname, user_nickname, user_password, user_email, user_hometown) VALUES (:firstname, :lastname, :nickname, :password, :email, :hometown)&quot;; $check = $pdo-&gt;prepare($query); $check-&gt;bindParam(':firstname', $userfirstname, PDO::PARAM_STR); $check-&gt;bindParam(':lastname', $userlastname, PDO::PARAM_STR); $check-&gt;bindParam(':nickname', $usernickname, PDO::PARAM_STR); $check-&gt;bindParam(':password', $userpassword, PDO::PARAM_STR); $check-&gt;bindParam(':email', $useremail, PDO::PARAM_STR); $check-&gt;bindParam(':hometown', $userhometown, PDO::PARAM_STR); $check-&gt;execute(); if ($check-&gt;rowCount() &gt; 0) { $msg = &quot;utente registrato&quot;; } else { $msg =&quot;utente non registrato&quot;; } } } } echo $msg; ?&gt;
  </code></pre>
  <p>if you also have any suggestions for the syntax, comments, it is welcome</p>