So the intention of this code is to: IF there is data inside of the config2.php file then you can login, but if there isnt (ELSE) then you need to go through the Database Connection Installer. I have tried several different variations and techniques but non has actually work. I will get both buttons showing or just one even thought the information has been POST to the config2.php file...
$installation = 'config/config2.php';
if ( strpos(file_get_contents($installation),$_GET['host']) !== true) {
echo "<br><p style='text-align: center'><strong>Lets get started, press the login button below to begin!</strong> <br><br>
<a href='#myModal' class='btn btn-primary' data-toggle='modal'>LOGIN</a></p> ";
echo "<div id='myModal' class='modal hide fade' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true'>
<div class='modal-header'>
<button type='button' class='close' data-dismiss='modal' aria-hidden='true'>×</button>
<h3 id='myModalLabel'>User Login</h3>
</div>
<div class='modal-body'>
<form action='login.php' method='post'>
<table>
<tr style='text-align: center'>
<td>Username: </td>
<td><input type='text' name='email' placeholder='Your Simple Invoices Username' /></td>
</tr>
<tr style='text-align: center'>
<td>Password: </td>
<td><input type='password' name='password' placeholder='Password' /></td>
</tr>
</table>
</div>
<div class='modal-footer'>
<button class='btn btn-danger' data-dismiss='modal' aria-hidden='true'>Close</button>
<input class='btn btn-success' type='submit' name='submit' value='Login' />
</div>
</div>";
} else ( strpos(file_get_contents($installation),$_GET['host']) !== false); {
echo "<br><br>";
echo "<p style='text-align: center'>You need to install to use it!</p>";
echo "<p style='text-align: center'><a href='#myModal2' class='btn btn-success' data-toggle='modal'>INSTALL!</a></p>";
echo "<div id='myModal2' class='modal hide fade' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true'>
<div class='modal-header'>
<button type='button' class='close' data-dismiss='modal' aria-hidden='true'>×</button>
<h3 id='myModalLabel'>Database Connection Installer</h3>
</div>
<div class='modal-body'>
<form action='install.php' method='post'>
<table>
<tr style='text-align: center'>
<td>Database Address: </td>
<td><input type='text' name='host' placeholder='Database Host' /></td>
</tr>
<tr style='text-align: center'>
<td>Database Username: </td>
<td><input type='text' name='username' placeholder='Database Username' /></td>
</tr>
<tr style='text-align: center'>
<td>Database Password: </td>
<td><input type='text' name='password' placeholder='Database Password' /></td>
</tr>
<tr style='text-align: center'>
<td>Database Name: </td>
<td><input type='text' name='db_name' placeholder='Database Name' /></td>
</tr>
</table>
</div>
<div class='modal-footer'>
<button class='btn btn-danger' data-dismiss='modal' aria-hidden='true'>Close</button>
<input class='btn btn-success' type='submit' name='submit' value='Connect' />
</div>
</div>";
}
Here is where you went wrong:
else ( strpos(file_get_contents($installation),$_GET['host']) !== false);
The else part should not have a statement.
Maybe you are looking for a else if
statement http://php.net/manual/en/control-structures.elseif.php
I just saw the else part. The other users also saw other errors in your code. Best you check your code with the Manual to find out the proper usage of php.
According to Comparison Operators, ===
/ !==
both ends "must" be the same type, you are comparing an int to a boolean.
For the sake of completion,
} else ( strpos(file_get_contents($installation),$_GET['host']) !== false); {
should be
} else if ( strpos(file_get_contents($installation),$_GET['host']) !== false) {
without the ;
.
Do it this way:
if (strpos(file_get_contents($installation),$_GET['host']) !== false) {
// Do stuff for string found
} else {
// Do stuff for string not found
}
The problem is that strpos
never returns true
. It either returns a number (the position of the found substring) or false
if the substring is not found. You don't need else if
, since you only care about whether the string is found or not, there are no other cases.
Try:
if ( strpos(file_get_contents($installation),$_GET['host'])) {
Instead of
if ( strpos(file_get_contents($installation),$_GET['host']) !== true) {