Registration code to select from Database;
<?php
$Config = mysqli_fetch_object($Confi = mysqli_query(“SELECT * FROM Configuration”));
if ($Config->Register == “true”) { echo “?”; } else { echo “!”; } ?>
Connection to Database;
<?php
$servername = “localhost”;
$username = “username”;
$password = “password”;
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); }
echo “Connected successfully”; ?>
Had to reformat your code as I could not read it in your version!
Well, the second section of your code is basically a simple connection to the database. Looks normal.
That should be the first part of your program. It is used only once on a page. After that, you can use it
over and over as needed using the $conn-> format. Then, once the connection is made you use that
as the base for the second part. But, in the second part (which you listed first) you did not refer back to
the actual connection. Therefore, swap the order of these and alter the registration code to something
like this:
Registration code to select from Database;
<?php
$query = “SELECT * FROM Configuration”;
$results = mysqli_query($conn, $query);
$Config = mysqli_fetch_object($results);
if ($Config->Register == “true”) { echo “?”; } else { echo “!”; }
?>
Note that I altered the code to be more readable. You use OOP for part of your code and not for other parts. (OOP is Object Orientated Programming) Normally, you pick one and use it. Your creation of the connection and the query is not done in OOP and the compare is. It still should work that way. Just explaining your code since you are new to this. So, move your connection above the query or registration second and fix the variable names and let us know if it works for you.