I'm using a form to post values to my PHP class.
<?php
if(!empty($_POST)){
require_once('../../handling/admin_add_user.php');
$add_username = $_POST['add_username'];
$add_email = $_POST['add_email'];
$add_gender = $_POST['add_gender'];
$add_server = $_POST['add_server'];
$add_coins = $_POST['add_coins'];
$user_add = new admin_add_user($add_username, $add_email, $add_gender, $add_server, $add_coins);
$user_add_response = $user_add->class_handler();
echo $user_add_response;
}
?>
And inside the function class_handler im checking if the value for the $this->coins parameter is empty using the isset function sadly the function would always return the error message incase i would put a 0 as value.
<?php
class admin_add_user extends database {
function __construct($username, $email, $gender, $server, $coins){
$this->username = $username;
$this->email = $email;
$this->gender = $gender;
$this->server = $server;
$this->coins = $coins;
}
function add_user(){
$this->connect();
$this->execute_query("INSERT INTO Users (username, email, gender, server, active, activate_key, coins) VALUES ('" . $this->username . "', '" . $this->email . "', '" . $this->gender . "', '" . $this->server . "', 1, 0, " . $this->coins . ")");
}
function class_handler(){
if(!$this->username){
return 'Please enter a username.';
}else if(!$this->email){
return 'Please enter a email.';
}else if(!$this->gender){
return 'Please select a gender.';
}else if(!$this->server){
return 'Please select a server.';
}else if(isset($this->coins)){
return 'Please enter a coin value. eG: 0';
}else{
$this->add_user();
return 'Succesfull added the following account to the database: ' . $this->username;
}
}
}
?>
How could I manage to check if the $this->coins variable is NOT empty but could contain the int 0?