Note that there are some explanatory texts on larger screens.

plurals
  1. POBeing sent to a different part of the website
    primarykey
    data
    text
    <p>I'm working on a register form, for my website.</p> <pre><code>&lt;?php include('config.php'); if(isset($_SESSION['username'])) { header('Location:index.php'); } if(isset($_POST['submit-registerform'])) { Register(); } function Register() { if(!empty($_POST['username']) &amp;&amp; !empty($_POST['password']) &amp;&amp; !empty($_POST['lastname']) &amp;&amp; !empty($_POST['email'])) { // Database Connection: require('config.php'); $MyConnection = new PDO('mysql:host=x;dbname=x', $dbusername, $dbpassword); $MyConnection-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Information from user: $username = htmlspecialchars($_POST['username']); $password = htmlspecialchars($_POST['password']); $lastname = htmlspecialchars($_POST['lastname']); $email = htmlspecialchars($_POST['email']); // Hashing the password: $cost = 10; $salt = strtr(base64_encode(mcrypt_create_iv(16, MCRYPT_DEV_URANDOM)), '+', '.'); $salt = sprintf("$2a$%02d$", $cost) . $salt; $hash = crypt($password, $salt); // Check if username already exists in the database: $findUser = $MyConnection-&gt;prepare("SELECT Username FROM Users WHERE Username = :username OR Email = :email"); $findUser-&gt;bindParam(':username', $username); $findUser-&gt;bindParam(':email', $email); $findUser-&gt;execute(); $foundUser = $findUser-&gt;fetch(PDO::FETCH_OBJ); if($username == $foundUser-&gt;Username) { echo ' &lt;div id="pop-up"&gt; This username is already in use. Please choose another one. &lt;/div&gt; '; } elseif($email == $foundUser-&gt;Email) { echo ' &lt;div id="pop-up"&gt; This email address is already in use. Please sign up with a different one. &lt;br /&gt; If this is impossible, please &lt;a href="contact.php"&gt;contact us&lt;/a&gt;. &lt;/div&gt; '; } else { // Store information into the database: $sql = $MyConnection-&gt;prepare("INSERT INTO Users (Username, Password, Lastname, Email) VALUES (:username, :password, :lastname, :email"); $sql-&gt;bindParam(':username', $username); $sql-&gt;bindParam(':password', $hash); $sql-&gt;bindParam(':lastname', $lastname); $sql-&gt;bindParam(':email', $email); if($sql-&gt;execute()) { echo ' &lt;div id="pop-up"&gt; Your account has succesfully been registered. You can start using it right away, by clicking &lt;a href="login.php"&gt;here&lt;/a&gt;. &lt;/div&gt; '; } } } } ?&gt; </code></pre> <p>When I fill in information in my form, and I already use a username that I have stored into my database, I get the right pop-up, displaying that that username is already in use. But when I fill in different information (with or without the same email address) I get sent to another webpage, which doesn't exist, so my hosts takes over and displays their error screen.</p> <p>Does anybody know why it sends the visitor of the webpage to another page (that doesn't exist)?</p> <p>Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload