R
R
Roman Grigoriev2016-01-26 10:32:37
PHP
Roman Grigoriev, 2016-01-26 10:32:37

Why does html disappear when parsing php?

There is a registration window that appears when you click on one of the buttons in the navigation. I made the appearance through JQuery.

<div>
    <div class="col-md-8" id="popreg">

                <p>Registration</p> <!--RUNS-->
             
                <?php include_once "register.php";
                ?>

                <form method="post" action="logged.php"> <!--DOES NOT RUN-->
                    <p>
                        <input type="text" size="16" name="username" placeholder="username" required/>
                    </p>
                    <p>
                        <input type="text" size="16" name="email" placeholder="email" required/>
                    </p>
                    <p>
                        <input type="password" size="16" name="password" placeholder="password" required/>
                    </p>
                    <p>
                        <input type="password" size="16" name="check_password" placeholder="Repeat password" required/> <br>
                    </p>
                    <p id="signbutton">
                        <input type="submit" size="16" name="submit" value="Sign in"/>
                    </p>
                </form>
    </div>
</div>

(If I'm doing something crooked (unprofessionally) - a huge request to be sure to say. Maybe I'm making a site like it was done in the 90s - if so, I'll be glad to hear :) I rely on forums and literature, I understand that there may be errors).
The fact is that the field of how I included <?php?> in the html file disappears everything that is after this <?php?> fragment - in this case, these are the input fields that are needed for registration.
Here's how it should look like: (There's just no <?php?> inserted here)
c6af3943df014f7cb186c8ca1424352b.png
And here's how it actually is - with <?php?>
That is, everything after php disappears.
370982d9479449e4b3eaac5c8a024701.png
Here is the php code: register.php
(Again, I understand that there may be something wrong, and that writing code through include_once is not cool, but I read this on the site.)
<?php
  # SQL CONNECTION
  $connect = mysql_connect('localhost:8889', 'root', '12439524') or die(mysql_error());
  mysql_select_db('pumprate');

  # REGISTRATION CHECK
  if (isset($_POST["submit"])) {
    $username = $_POST["username"];
    $email = $_POST["email"];
    $password = $_POST["password"];
    $check_password = $_POST["check_password"];

    # CHECKS PASSWORD AND IT'S CONFIRMATION
    if ($password == $check_password) {

      # WEAK CODE PROTECTION
      $password = md5($password);

      # CREATE A QUERY
      $query = mysql_query("INSERT INTO users VALUES ("","$username","$password")") or die(mysql_error());
    } else {
        # PAGE THAT ERRORS WRONG PASSWORDS
        die('Passwords must match!')
        };
  }
?>

I've read that you shouldn't use or die - but I can't think of a replacement.
Thanks in advance for any criticism and replies :]

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vyacheslav Barsukov, 2016-01-26
@slavabars

<?php
  # SQL CONNECTION
  $connect = mysql_connect('localhost:8889', 'root', '12439524') or die(mysql_error());
  mysql_select_db('pumprate');

  # REGISTRATION CHECK
  if (isset($_POST["submit"])) {
    $username = $_POST["username"];
    $email = $_POST["email"];
    $password = $_POST["password"];
    $check_password = $_POST["check_password"];

    # CHECKS PASSWORD AND IT'S CONFIRMATION
    if ($password == $check_password) {

      # WEAK CODE PROTECTION
      $password = md5($password);

      # CREATE A QUERY
      $query = mysql_query("INSERT INTO users VALUES ('','$username','$password')") or die(mysql_error());
    } else {
        # PAGE THAT ERRORS WRONG PASSWORDS
        die('Passwords must match!');
        }
  }
?>

Error in code
die('Passwords must match!')
        };

S
Silm, 2016-01-26
@Silm

There are at least two errors.
In line 20, there is a confusion with quotes, it should be:
and in general esteem about PDO.
in line 25 there is no sign ";".
Check that you have error display enabled in PHP, view the source code of the fragment in which you are performing the include in the browser, there should be an error message indicating the problem.
How to write in PHP: www.phptherightway.com

B
Barmunk, 2016-01-26
@Barmunk

Do not work directly with the base.
Rewrite the connection with at least mysqli .
Use Prepared Queries instead of directly passing variables to the sql query.
Write a function that will clean up garbage from variables .
Install an editor with a simple validator to avoid problems with the code.
Well, at the very end, you can close the connection to the database.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question