PHP Register Error

Kristopher

Photographer
Dec 25, 2010
802
66
Please don't judge however I'm trying to post values from a registration into a database and for some reason its throwing me a error and now allowing me to however the page is completely white. I've been away from Website development and I don't know much PHP and if someone could help me to at least get the information to submit so I can work on Login error messages and what not that would be extremely helpful!

<?php
$db_server = "localhost";
$db_username = "root";
$db_password = "King12";
$db_database = "ares";


$regiuser=$_POST['regiuser'];
$motto=$_POST['motto'];
$email=$_POST['email'];
$password1=$_POST['password'];


$conn = new PDO("mysql:host=$db_server;dbname=$db_database", $db_username, $db_password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);


$sql = "INSERT INTO users (username, motto, password, email, credits, duckets, rank)
VALUES ('$regiuser', '$motto', '$password1', '$email', '250', '5000', '1')";


$conn->exec($sql);
echo "<script>alert('Account successfully added'); window.location='index.php'</script>";

?>

The form:
<form method="post" action="register.php">
<input class="input" type="text" name="regiuser" style="margin-top:21px;">
<i class="fa fa-user-o" aria-hidden="true" style="margin-top:33px;"></i>
<input class="input" type="text">
<i class="fa fa-envelope" aria-hidden="true"></i>
<input class="input" type="password" name="password">
<i class="fa fa-lock" aria-hidden="true"></i>
<input class="input" type="Text" name="Motto">
<i class="fa fa-lock" aria-hidden="true"></i>
<input class="subinput" type="submit" value="Registrieren">
</form>
 

Laynester

a bad bitch
Nov 7, 2018
304
422
What does the error say...
Post automatically merged:

Also there is no post either
you would need to add an if statement like if(isset($_POST['thing'])) {}
then put ur regiuser = stuff in there along with the insert statement..
 

BIOS

ಠ‿ಠ
Apr 25, 2012
906
247
No error messages not really much to go on...

But you're missing a name on one of the input fields, assuming you wanted that to be the email. That's likely cause.

This is likely what you wanted but I haven't tested it so you might need to change it:
PHP:
// register.php
<?php

$db_server = "localhost";
$db_username = "root";
$db_password = "King12"; // change me
$db_database = "ares"; // change me

// Check if the fields are actually set..
if (
    !isset($_POST) ||
    empty($_POST["regiuser"]) ||
    empty($_POST["motto"]) ||
    empty($_POST["email"]) ||
    empty($_POST["password"])
) {
    print "Missing required fields...";
    exit;
}

$regiuser = $_POST["regiuser"];
$motto = $_POST["motto"];
$email = $_POST["email"];
$password = $_POST["password"];

$conn = new PDO("mysql:host=$db_server;dbname=$db_database", $db_username, $db_password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$sql = "INSERT INTO users (username, motto, password, email, credits, duckets, rank) VALUES (?,?,?,?,?,?,?)";
$res = $conn->prepare($sql)->execute([$regiuser, $motto, $password, $email, "250", "5000", "1"]);

// If success, redirect to index.php
if ($res) {
    print "Account successfully added...";
    header("Location: index.php");
    exit;
}

?>

<form method="POST" action="register.php">
    <input class="input" type="text" name="regiuser" style="margin-top:21px;">
    <i class="fa fa-user-o" aria-hidden="true" style="margin-top:33px;"></i>
    <input class="input" type="text" name="email">
    <i class="fa fa-envelope" aria-hidden="true"></i>
    <input class="input" type="password" name="password">
    <i class="fa fa-lock" aria-hidden="true"></i>
    <input class="input" type="text" name="motto">
    <i class="fa fa-lock" aria-hidden="true"></i>
    <input class="subinput" type="submit" value="Registrieren">
</form>
 

Users who are viewing this thread

Top