Hi there, I'm looking for some guidance with counting the # of rows from a query, please see below (I had this working fine when posting the variable).
Model
Code:
// Get Proxy Rules
function getAllRule($ip_address,$client_id){
$result = $this->query("SELECT * FROM reverse_proxy_rules WHERE ipaddress='$ip_address' AND cust_id=$client_id");
$num_rows = mysql_num_rows($result);
return $result;
}
Controller
Code:
// Add Rule Method
function addRule(){
$proxy_id = $_POST['proxy_id'];
$this->loadLibrary('formvalidator.class');
if($user = $this->logged_in())
{
if($user['group_id']==1)
{
/**
* If $_POST data isn't set, form has
* not been submitted, load with no
* errors
*/
if(!isset($_POST['bindaddress']) && !isset($_POST['bindport']) && !isset($_POST['connectaddress']) && !isset($_POST['connectport']))
{
$this->redirect('navigator/view2/'.$id);
}
else
{
$bindaddress = $_POST['bindaddress'];
$bindport = $_POST['bindport'];
$connectaddress = $_POST['connectaddress'];
$connectport = $_POST['connectport'];
$maxrule = $num_rows;
/**
* Validate user input for the new
* project
*/
$validator = new FormValidator();
$bindaddress_rule = $validator->run($bindaddress, 'SRC IP Address', 'required|clean');
$bindport_rule = $validator->run($bindport, 'SRC Port', 'required|clean');
$connectaddress_rule = $validator->run($connectaddress, 'Destination IP address', 'required|clean');
$connectport_rule = $validator->run($connectport, 'Destination Port', 'required|clean');
$maxrule_rule = $validator->run($maxrule, 'Maximum Rules', 'clean');
/**
* Reload the form if there are errors
*/
if ($validator->has_errors == true)
{
//echo "test21";
$this->set('bindaddress', $bindaddress_rule);
$this->set('bindport', $bindport_rule);
$this->set('connectaddress', $connectaddress);
$this->set('connectport', $connectport_rule);
$this->set('error_list', $validator->error_list);
//echo $validator->error_list;
$this->loadModel('Project');
$proxy = $this->Project->proxy_details($proxy_id);
$this->set('proxy', $proxy);
$this->loadView('view-proxy');
//$this->redirect('navigator/view2/'.$proxy_id);;
}
else if($bindport<1 || $bindport>65535){
$this->set('error_list', '<div class="error">Incorrect SRC Port</div>');
$this->loadModel('Project');
$proxy = $this->Project->proxy_details($proxy_id);
$this->set('proxy', $proxy);
$this->loadView('view-proxy');
}
else if($connectport<1 || $connectport>65535){
$this->set('error_list', '<div class="error">Incorrect Destination Port</div>');
$this->loadModel('Project');
$proxy = $this->Project->proxy_details($proxy_id);
$this->set('proxy', $proxy);
$this->loadView('view-proxy');
}else if(filter_var($connectaddress, FILTER_VALIDATE_IP) == false){
$this->set('error_list', '<div class="error">Incorrect Destination IP</div>');
$this->loadModel('Project');
$proxy = $this->Project->proxy_details($proxy_id);
$this->set('proxy', $proxy);
$this->loadView('view-proxy');
}
else if($maxrule>=5){
$this->set('error_list', '<div class="error">You have exceeded your amount of allocated rules, please contact support.</div>');
$this->loadModel('Project');
$proxy = $this->Project->proxy_details($proxy_id);
$this->set('proxy', $proxy);
$this->loadView('view-proxy');
}
else
{
Anyone know where I'm going wrong?