I'm having some trouble with executing code after I call a function. When I execute this code, it connects to the server fine in the try function, "PreEchoTest" is displayed but when CheckUsername(); is called, no echo functions come after that, not even the echoes inside of the CheckUsername() function.
The SQL Query is correct as I've tried Querying it directly to the SQL server. I'm not being displayed errors when I load the code, but I'm wondering why nothing is echoing when the function CheckUsername(); happens. I'm thinking maybe there is an error in there and that's stopping execution? Anyone know?
try
{
$conn = new PDO({Server Details Are Here});
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "PreEchoTest";
CheckUsername();
echo "AfterEchoTest";
}
catch (PDOException $e)
{
print("Error connecting to Server.");
die(print_r($e));
}
function CheckUsername()
{
$sql = "SELECT Username FROM Students UNION SELECT Username FROM Parents";
$result = $conn->query($sql);
//Show data for each row.
while ($row = $result->fetch(PDO::FETCH_ASSOC))
{
if ($username == $row['Username'])
{
echo "Success";
//CheckUserPassword($row['Username']);
}
else
{
echo "Fail";
}
}
}