0

I'm a rookie amateur trying to build my own site that uses PHP and a backend SQL database. Having got all my pages working with the database on an Apache II localhost, I have now moved my files to a commercial hosting service. Post migration, some of the pages have gone blank. I have narrowed the problem down to a block of php code that runs as follows:

    <?php
    if (isset($_POST['submit3'])) {
      $email = htmlentities($_POST['email']);
      $password = htmlentities($_POST['password']);
        if (empty($email) || empty($password))  {
    echo <<<EOF
    <script type="text/javascript">
    $(".welcome").hide();
    $("#form3").hide();
    $("#error").show();
    </script>
    EOF;
    }
        else    {
          $sql = "SELECT `email` FROM `Registrations` WHERE `email` = '".$email."' AND `password` = '".$password."'";
          $rs = $connection->query($sql);

        if ($rs->num_rows === 0) {
    echo <<<EOF
    <script type="text/javascript">
    $(".welcome").hide();
    $("#form3").hide();
    $("#nomatch").show();
    </script>
    EOF;
    }
        else {
          $_SESSION["email"] = "$email";
    echo <<<EOF
    <script type="text/javascript">
    window.location = "PharMEdCentral-MyAccount.php";
    </script>
    EOF;
    } 

      $rs->free();
      }
    }
    ?>

The html renders well when these two lines are commented out, but I get blank page with these line in. It's probably a silly thing but I have been unable to figure out what mistake I'm making. The problem is not with the connection to the database as other pages with the same connection are rendered properly.

The server version is MySQL 5.6.26 via UNIX socket.

Would highly appreciate any tips on how to fix this!

Shoibal
  • 1
  • 2
  • Check whether you have enabled `mysqli` in your server, because some server won't enabled it. – Vignesh Chinnaiyan Sep 19 '16 at 09:52
  • You can refer this [http://stackoverflow.com/a/26421243/6374322](http://stackoverflow.com/a/26421243/6374322) – Vignesh Chinnaiyan Sep 19 '16 at 09:54
  • Yes, mysqli is enabled and I have no problems with other pages of the site that use mysqli and access the same database. I think the problem is with my php code that runs fine on my hard disk but not on the commercial server. I will edit the original post to show you the whole php block that is causing the problem. – Shoibal Sep 21 '16 at 05:49
  • Managed to solve the problem. All pages on the site are now rendering satisfactorily and connecting appropriately to the database. For the benefit of those who may be facing similar problems, here are a few learnings from my experience: – Shoibal Sep 25 '16 at 07:35
  • 1) An obvious issue with moving files is the defined path to linked files. Cross-check all href/location tags and path to 'include' files. 2) Check definitions for the database connection. If db name, db username, or db password were changed you will need to update the code. 3) Found that somehow, on migration, the hard return between some lines of code had disappeared. E.g, 'EOF;' and '}' placed on separate lines had gotten concatenated to 'EOF; }'. This, obviously wouldn't fly. 4) The '#' notation, used for any purpose other than id selector, can be a problem. I had to change "#" to "No." – Shoibal Sep 25 '16 at 08:22

0 Answers0