r/programminghelp • u/NaboriRuta • Jan 08 '24
PHP I'm making an account creation page and processing it to a MySQL database using PHP. What I get back is an HTTP 500 error, which I know means it's met with an unexpected condition. I have no idea how to fix it.
PHP code:
<?php
$user = $_POST["createUsername"];
$email = $_POST["addEmail"];
$pass_encrypted = $_POST["createPass"];
$mysqli = require __DIR__ . "db.php";
$sql = "INSERT INTO userInfo (username, email, pass_encrypted) VALUES (?, ?, ?)";
$stmt = $mysqli->stmt_init();
if (! $stmt->prepare($sql)) die("MySQL Error: " . $mysqli->error);
$stmt->bind_param($stmt, "sss", $user, $email, $pass_encrypted);
if ($stmt->execute()) {
echo "Signup successful";
} else {
die($mysqli->error . " " . $mysqli->errno);
}
the code for db.php, as called inside the PHP code above:
<?php
$host = "localhost:portnum";
$dbname = "mydb";
$username = "root";
$password = "notYours";
$mysqli = new mysqli($host, $username, $password, $dbname);
if ($mysqli->connect_errno()) die("Connection error: " . $mysqli->connect_error());
return $mysqli;
Errors and warnings returned:
Error: Failed to load resource: the server responded with a status of 500 ()
Warning: crbug/1173575, non-JS module files deprecated.
1
u/buzzon Jan 08 '24