PHP Registration Form with PHP & MySQL

RaggedClinic13

New member
This is my code. I'm creating a game. The address to the game or shall I say, this page, is ecolina.eu/r.php; I have not decided yet if it's going to be a game about horses or cats. But I need help with my code. There is something wrong with the if-statements! When I use this if-statement (in the beginning of the page), it posts the same sentence twice "New record created successfully". But the text doesn't disappear when you enter the game again.

PHP:
<?php

require_once 'dg/connect.php';

$FirstName    = $_POST['FirstName'];
$LastName     = $_POST['LastName'];
$Username     = $_POST['Username'];
$Password     = $_POST['Password'];
$Email        = $_POST['Email'];

$Link = "INSERT INTO Users (FirstName, LastName, Username, Password, Email, REG_DATE) VALUES ('$FirstName', '$LastName', '$Username', '$Password', '$Email', NOW())";

if (!mysqli_query($Conn, $Link)) {
    echo "New record created successfully";
} else {
    echo "Error: " . $Link . "<br>" . mysqli_error($Conn);
}

?>

<!DOCTYPE html>
    <html>
    <head>
<title>Ecolina.eu // Epic Horse Game!</title>
<meta http-equiv="content-type" charset="UTF-8">
<link rel="stylesheet" type="text/css" href="sandwich-has-style.css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
<body>
    <div id="Container">
    <div id="Header">
    <h1><a href="#">Ecolina.eu</a></h1>
</div>

        <!-- Att dom är IS-terrorister -->

    <div id="Wrapper">
    <div id="Content">
    <div id="Extra">
        <p><strong>More stuff here.</strong></p>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec nec nibh gravida, porta dolor et, eleifend ante. Nullam placerat neque a blandit ultrices. Vestibulum at diam in dolor interdum placerat. Sed nunc arcu, mattis a bibendum vel, tincidunt dictum nisl. Aliquam erat volutpat. Mauris est dui, consectetur eget euismod ac, finibus accumsan velit. Phasellus suscipit posuere lorem quis dictum. Vestibulum pharetra pellentesque arcu, sed congue nunc mattis at.
        </div>
      <p><strong>Heading #1</strong></p>
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec nec nibh gravida, porta dolor et, eleifend ante. Nullam placerat neque a blandit ultrices. Vestibulum at diam in dolor interdum placerat. Sed nunc arcu, mattis a bibendum vel, tincidunt dictum nisl. Aliquam erat volutpat. Mauris est dui, consectetur eget euismod ac, finibus accumsan velit. Phasellus suscipit posuere lorem quis dictum. Vestibulum pharetra pellentesque arcu, sed congue nunc mattis at.
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec nec nibh gravida, porta dolor et, eleifend ante. Nullam placerat neque a blandit ultrices. Vestibulum at diam in dolor interdum placerat. Sed nunc arcu, mattis a bibendum vel, tincidunt dictum nisl. Aliquam erat volutpat. Mauris est dui, consectetur eget euismod ac, finibus accumsan velit. Phasellus suscipit posuere lorem quis dictum. Vestibulum pharetra pellentesque arcu, sed congue nunc mattis at.
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec nec nibh gravida, porta dolor et, eleifend ante. Nullam placerat neque a blandit ultrices. Vestibulum at diam in dolor interdum placerat. Sed nunc arcu, mattis a bibendum vel, tincidunt dictum nisl. Aliquam erat volutpat. Mauris est dui, consectetur eget euismod ac, finibus accumsan velit. Phasellus suscipit posuere lorem quis dictum. Vestibulum pharetra pellentesque arcu, sed congue nunc mattis at.
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec nec nibh gravida, porta dolor et, eleifend ante. Nullam placerat neque a blandit ultrices. Vestibulum at diam in dolor interdum placerat. Sed nunc arcu, mattis a bibendum vel, tincidunt dictum nisl. Aliquam erat volutpat. Mauris est dui, consectetur eget euismod ac, finibus accumsan velit. Phasellus suscipit posuere lorem quis dictum. Vestibulum pharetra pellentesque arcu, sed congue nunc mattis at.
    </div>
            </div>
  <div id="Navigation">
    <p><strong>Register An Account! Accountability</strong></p>
    <ul>
      <form id="Gurkis" method="POST" action="r.php">
      Användarnamn: <input type="text" name="Username">&nbsp;<?php if (empty($_POST['Username'])) { echo $Sql; } ?><br>
      Förnamn: <input type="text" name="FirstName">&nbsp;<?php if (empty($_POST['FirstName'])) { echo $Sql; } ?><br>
      Efternamn: <input type="text" name="LastName">&nbsp;<?php if (empty($_POST['LastName'])) { echo $Sql; } ?><br>
      Lösenord: <input type="password" name="Password">&nbsp;<?php if (empty($_POST['Password'])) { echo $Sql; } ?><br>
      Email: <input type="email" name="Email"><br><br>
      
                  <input type="checkbox" id="Roots" value="Agree">
                  <label for="Roots">Jag Godkänner spelets Regler & Villkor!*</label><br><br>
      
        <!-- Hi there. Phew! This has been quite a journey. I am in the middle of creating a game. I am very thrilled, but I can't stand the fact that Josefine's mamma is trying to spoil my code. I have, however, removed the evil code from my script. -->
      
       <input type="submit" value="Registrera konto!*"><br><br>
       <sub>*128-bit Encryption</sub>
        </form>
            </ul>
                </div>
                    <div id="Footer">
                        <p><?php echo "Copyright &copy; Lurking Games AB";?></p></table>
  
        <!-- With 128 AES-encryption* -->
      
        <!-- Jag tar gärna ett glas rött med dig -->
      
        <!-- 3.60 GhZ -->
 
    </div>
    </div>
  
    <!-- Signed Eilis -->
  
</body>
</html> <!-- End of file -->
 
This is my latest code (not working yet)

PHP:
<?php

require_once 'dg/connect.php';

    /* I am trying to create a mysql query. Inside of the submit if-loop, there is one or two statements that run a mysql query command. My problem is: it's not working. I don't know how to make This
    work but I am fully proper */

     $FirstName    = $_POST['FirstName'];
     $LastName     = $_POST['LastName'];
     $Username     = $_POST['Username'];
     $Password     = $_POST['Password'];
     $Email        = $_POST['Email'];

    // $Link = "INSERT INTO Users (FirstName, LastName, Username, Password, Email, REG_DATE) VALUES ('$FirstName', '$LastName', '$Username', '$Password', '$Email', NOW())";

    if (isset($_POST['submit'])) {
        $Link = "INSERT INTO Users (FirstName, LastName, Username, Password, Email, REG_DATE) VALUES ('$FirstName', '$LastName', '$Username', '$Password', '$Email', NOW())";
        echo "New record created successfully";
        } else {
        echo "Error: " . $Link . "<br>" . mysqli_error($Conn);
        }

    // Rustik

?>

<!DOCTYPE html>
    <html>
    <head>
<title>Obelique.se // Epic Cat Game!</title>
<meta http-equiv="content-type" charset="UTF-8">
<link rel="stylesheet" type="text/css" href="sandwich-has-style.css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
<body>
    <div id="Container">
    <div id="Header">
    <h1><a href="#">Ecolina.eu</a></h1>
</div>

        <!-- Att dom är IS-terrorister -->

    <div id="Wrapper">
    <div id="Content">
    <div id="Extra">
        <p><strong>More stuff here.</strong></p>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec nec nibh gravida, porta dolor et, eleifend ante. Nullam placerat neque a blandit ultrices. Vestibulum at diam in dolor interdum placerat. Sed nunc arcu, mattis a bibendum vel, tincidunt dictum nisl. Aliquam erat volutpat. Mauris est dui, consectetur eget euismod ac, finibus accumsan velit. Phasellus suscipit posuere lorem quis dictum. Vestibulum pharetra pellentesque arcu, sed congue nunc mattis at.
        </div>
      <p><strong>Heading #1</strong></p>
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec nec nibh gravida, porta dolor et, eleifend ante. Nullam placerat neque a blandit ultrices. Vestibulum at diam in dolor interdum placerat. Sed nunc arcu, mattis a bibendum vel, tincidunt dictum nisl. Aliquam erat volutpat. Mauris est dui, consectetur eget euismod ac, finibus accumsan velit. Phasellus suscipit posuere lorem quis dictum. Vestibulum pharetra pellentesque arcu, sed congue nunc mattis at.
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec nec nibh gravida, porta dolor et, eleifend ante. Nullam placerat neque a blandit ultrices. Vestibulum at diam in dolor interdum placerat. Sed nunc arcu, mattis a bibendum vel, tincidunt dictum nisl. Aliquam erat volutpat. Mauris est dui, consectetur eget euismod ac, finibus accumsan velit. Phasellus suscipit posuere lorem quis dictum. Vestibulum pharetra pellentesque arcu, sed congue nunc mattis at.
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec nec nibh gravida, porta dolor et, eleifend ante. Nullam placerat neque a blandit ultrices. Vestibulum at diam in dolor interdum placerat. Sed nunc arcu, mattis a bibendum vel, tincidunt dictum nisl. Aliquam erat volutpat. Mauris est dui, consectetur eget euismod ac, finibus accumsan velit. Phasellus suscipit posuere lorem quis dictum. Vestibulum pharetra pellentesque arcu, sed congue nunc mattis at.
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec nec nibh gravida, porta dolor et, eleifend ante. Nullam placerat neque a blandit ultrices. Vestibulum at diam in dolor interdum placerat. Sed nunc arcu, mattis a bibendum vel, tincidunt dictum nisl. Aliquam erat volutpat. Mauris est dui, consectetur eget euismod ac, finibus accumsan velit. Phasellus suscipit posuere lorem quis dictum. Vestibulum pharetra pellentesque arcu, sed congue nunc mattis at.
    </div>
            </div>
  <div id="Navigation">
    <p><strong>Register An Account! Accountability</strong></p>
    <ul>
      <form id="Gurkis" method="POST" action="r.php">
      Användarnamn: <input type="text" name="Username">&nbsp;<?php if (empty($_POST['Username'])) { echo $Sql; } ?><br>
      Förnamn: <input type="text" name="FirstName">&nbsp;<?php if (empty($_POST['FirstName'])) { echo $Sql; } ?><br>
      Efternamn: <input type="text" name="LastName">&nbsp;<?php if (empty($_POST['LastName'])) { echo $Sql; } ?><br>
      Lösenord: <input type="password" name="Password">&nbsp;<?php if (empty($_POST['Password'])) { echo $Sql; } ?><br>
      Email: <input type="email" name="Email"><br><br>
        
                  <input type="checkbox" id="Roots" value="Agree">
                  <label for="Roots">Jag Godkänner spelets Regler & Villkor!*</label><br><br>
        
        <!-- Hi there. Phew! This has been quite a journey. I am in the middle of creating a game. I am very thrilled, but I can't stand the fact that Josefine's mamma is trying to spoil my code. I have, however, removed the evil code from my script. -->
        
       <input type="submit" name="submit" value="Registrera konto!*"><br><br>
       <sub>*128-bit Encryption</sub>
        </form>
            </ul>
                </div>
                    <div id="Footer">
                        <p><?php echo "Copyright &copy; Lurking Games AB";?></p></table>
    
        <!-- With 128 AES-encryption* -->
        
        <!-- Jag tar gärna ett glas rött med dig -->
        
        <!-- 3.60 GhZ -->
 
    </div>
    </div>
    
    <!-- Signed Eilis -->
    
</body>
</html> <!-- End of file -->
 
Here is the finished script (almost working), need to update it though.

PHP:
<?php

require_once 'dg/connect.php';

    /* I am trying to create a mysql query. Inside of the submit if-loop, there is one or two statements that run a mysql query command. My problem is: it's not working. I don't know how to make This
    work but I am fully proper */

    // $Link = "INSERT INTO Users (FirstName, LastName, Username, Password, Email, REG_DATE) VALUES ('$FirstName', '$LastName', '$Username', '$Password', '$Email', NOW())";

     $FirstName    = $_POST['FirstName'];
     $LastName     = $_POST['LastName'];
     $Username     = $_POST['Username'];
     $Password     = $_POST['Password'];
     $Email        = $_POST['Email'];
     $TokenUtils   = "{4aadb081-4da1-4eeb-850c-594cefe3a042}";

if (isset($_POST['Submit']) && isset($_POST['Agree'])) {
    
    // Fix diz!
    $Gesult = mysqli_query($Conn, "INSERT INTO Users (FirstName, LastName, Username, Password, Email, REG_DATE) VALUES ('$FirstName', '$LastName', '$Username', '$Password', '$Email', NOW())");
    
    echo "New record created successfully";
        } else {
    echo "Error: " . $Gesult . "<br>" . mysqli_error($Conn);
                        } // Working!
                        
    // Update this!

    // Rustik

    // More here

?>

<!DOCTYPE html>
    <html>
    <head>
<title>Ethereal-princess.com // Epic Cat Game!</title>
<meta http-equiv="content-type" charset="UTF-8">
<link rel="stylesheet" type="text/css" href="sandwich-has-style.css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/site.webmanifest">
    </head>
<body>
    <div id="Container">
    <div id="Header">
    <h1><a href="register.php">#Ethereal-princess.com</a></h1>
</div>

        <!-- Att dom är IS-terrorister -->

    <div id="Wrapper">
    <div id="Content">
    <div id="Extra" style="margin-bottom: 20px;">
        <p><strong>More stuff here.</strong><br>
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec nec nibh gravida, porta dolor et, eleifend ante. Nullam placerat neque a blandit ultrices. Vestibulum at diam in dolor interdum placerat. Sed nunc arcu, mattis a bibendum vel, tincidunt dictum nisl. Aliquam erat volutpat. Mauris est dui, consectetur eget euismod ac, finibus accumsan velit. Phasellus suscipit posuere lorem quis dictum. Vestibulum pharetra pellentesque arcu, sed congue nunc mattis at.
        </div>
      <p><strong>Heading #1</strong></p>
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec nec nibh gravida, porta dolor et, eleifend ante. Nullam placerat neque a blandit ultrices. Vestibulum at diam in dolor interdum placerat. Sed nunc arcu, mattis a bibendum vel, tincidunt dictum nisl. Aliquam erat volutpat. Mauris est dui, consectetur eget euismod ac, finibus accumsan velit. Phasellus suscipit posuere lorem quis dictum. Vestibulum pharetra pellentesque arcu, sed congue nunc mattis at.
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec nec nibh gravida, porta dolor et, eleifend ante. Nullam placerat neque a blandit ultrices. Vestibulum at diam in dolor interdum placerat. Sed nunc arcu, mattis a bibendum vel, tincidunt dictum nisl. Aliquam erat volutpat. Mauris est dui, consectetur eget euismod ac, finibus accumsan velit. Phasellus suscipit posuere lorem quis dictum. Vestibulum pharetra pellentesque arcu, sed congue nunc mattis at.
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec nec nibh gravida, porta dolor et, eleifend ante. Nullam placerat neque a blandit ultrices. Vestibulum at diam in dolor interdum placerat. Sed nunc arcu, mattis a bibendum vel, tincidunt dictum nisl. Aliquam erat volutpat. Mauris est dui, consectetur eget euismod ac, finibus accumsan velit. Phasellus suscipit posuere lorem quis dictum. Vestibulum pharetra pellentesque arcu, sed congue nunc mattis at.
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec nec nibh gravida, porta dolor et, eleifend ante. Nullam placerat neque a blandit ultrices. Vestibulum at diam in dolor interdum placerat. Sed nunc arcu, mattis a bibendum vel, tincidunt dictum nisl. Aliquam erat volutpat. Mauris est dui, consectetur eget euismod ac, finibus accumsan velit. Phasellus suscipit posuere lorem quis dictum. Vestibulum pharetra pellentesque arcu, sed congue nunc mattis at.
    </div>
            </div>
  <div id="Navigation">
    <p><strong>Register An Account! Accountability</strong></p>
    <ul>
      <form id="Gurkis" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
      Användarnamn: <input type="text" name="Username" required>&nbsp;<?php if (empty($_POST['Username'])) { echo $Sql; } ?><br>
      Förnamn: <input type="text" name="FirstName" required>&nbsp;<?php if (empty($_POST['FirstName'])) { echo $Sql; } ?><br>
      Efternamn: <input type="text" name="LastName">&nbsp;<?php if (empty($_POST['LastName'])) { echo $Sql; } ?><br>
      Lösenord: <input type="password" name="Password" required>&nbsp;<?php if (empty($_POST['Password'])) { echo $Sql; } ?><br>
      Email: <input type="email" name="Email" required><br><br>
        
                  <input type="checkbox" id="Roots" value="Agree" name="Agree">
                  <label for="Roots">Jag Godkänner spelets Regler & Villkor!*</label><br><br>
        
        <!-- Hi there. Phew! This has been quite a journey. I am in the middle of creating a game. I am very thrilled, but I can't stand the fact that Josefine's mamma is trying to spoil my code. I have, however, removed the evil code from my script. -->
        
       <input type="submit" name="Submit" value="Registrera konto!*"><br><br>
       <sub>*WIPLASH-encryption</sub>
        </form>
            </ul>
                </div>
                    <div id="Footer">
                        <p><?php echo "Copyright &copy; Lurking Games AB";?></p></table>
    
        <!-- With 128 AES-encryption* -->
        
        <!-- Jag tar gärna ett glas rött med dig -->
        
        <!-- 3.60 GhZ -->
 
    </div>
    </div>
    
    <!-- Signed Eilis -->
    
</body>
</html> <!-- End of file -->
 
Back
Top