As part of a larger system, I have a piece of PHP code embedded in a web page to insert values into a database. However, it's returning a completely blank HTML page.
<?php
$mysqli = new mysqli("thing", "stuff", "morestuff", "otherstuff");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
$Name1 = $_POST['forename'];
$Name2 = $_POST['surname'];
$Email = $_POST['email'];
$Admin = $_POST['admin'];
$Pass = "password";
flag = 0;
$User = $Name1;
if (flag == 0) {
$SQLQuery2 = "INSERT INTO
Table1 (Forename, Surname, Admin, EmailAddress, Username, Password)
VALUES ('$Name1', '$Name2', '$Admin', '$Email', '$User', '$Pass');";
$mysqli->($SQLQuery2);
$contents = '<h1>User creation successful</h1>';}
else {$contents = '<h1>Error: Email address already in use.</h1>';}
?>
<html>
<head>
<title>Add User</title>
</head>
<body>
<?php
echo $contents;
?>
</body>
</html>
I've cut it down to this from the full system, and (although it's obviously not got the real connection details) the connection details are not the issue, as I'm using an identical SQL connection method elsewhere in my system, with identical details, and it works fine. All the post values are passed in correctly as well.
I've checked the semi-colons at least half a dozen times, and I don't have a clue what the issue could be. Could someone please help?
Edit: I've changed flag
to $flag
now, but I still have the same error. I've included
error_reporting(-1);
ini_set("display_errors", 1);
in the file right under <?php
but it's not doing anything.
Second edit: The other main issue was that mysqli->($SQLQuery2)
should be mysqli->query($SQLQuery2)
. I've fixed it and it's working now.