Please, for future notice, provide code or/and ideas that you have already tried. This is not the place to just ask people to do things for you.
class Database
{
protected $db;
public function __construct()
{
$this->db = new PDO("mysql:host=localhost;dbname=example","user","pass");
}
public function is_Empty($left,$right)
{
$search = $this->db
->prepare("SELECT * FROM table WHERE ... OR ...");
$search->execute(array(
':left' => $left,
':right' => $right
));
if($prepare->fetchAll() == null)? return false : return true;
}
}
The above code explains the principle, we're checking firstly if the person exists by using an SQL statement. Once the PDO executes the SQL query, it will return an Object. If the Object is null
then we know that the user does not exist so we return false
, if it does exist, we return true
.
You can then do something like so:
class DatabaseExtension extends Database
{
public function insert($name,$right, ect...)
{
$insert = $this->db->prepare("INSERT INTO...");
}
}
It can be called and used from $_GET
requests or $_POST
requests from a HTML web form which sends to a handler PHP file like so:
$dbHandler = new Database;
$dbHandler->inserting = new DatabaseExtension;
if($dbHandler->is_Empty($_GET['left'],$_GET['right']):
$dbHandler->insert($_GET['name'],$_GET['right'],etc...);
else:
echo "Sorry, this sponsor is already filled...";
endif;
This code is NOT exact and will not be your solution. It is to give you an idea scope to solve your problem.
Also note that is method is very Object-Orientated so if you're unfamiliar with any of this code or the use of Classes, I suggest you research before you create another post like: "What is a Class, Please make this for me."
There are plenty of other Connection protocols/API's you can use rather than PDO although I'd recommend PDO due to both SQLi,SQL (and if you're just plain... urgh...) ODBC becoming very depreciated in newer versions of PHP.