This is my 2nd web app in CI.
I am trying to grab a single value from a form (upon submit) and insert it into a database.
I have a controller “urlsubmission”:
<?php
class Urlsubmission extends CI_Controller{
function index() {
$this->load->model('domaincheckmodel');
$this->domaincheckmodel->verifyduplicates();
}
}
?>
a model (domaincheckmodel) – which searches the db for a any duplicates:
<?php
class Domaincheckmodel extends CI_Model{
function __construct(){
// Call the Model constructor
parent::__construct();
}
function verifyduplicates(){
#PREPARE DATA
$sql = "SELECT tld from ClientDomain WHERE tld = ?";
$postedTLD = $_POST['urlInput']; // Get unsanitized data
$endquery = $this->db->query($sql,array($this->db->escape_str($postedTLD))); // Query db
#CONDITION
if($endquery->num_rows() > 0){
$this->load->view('err/domainexists'); ##domain already used
## please login..
}
else{ #number of rows must be 0, insert into db
$newDomain = "INSERT INTO ClientDomain(tld) VALUES('".$this->db->escape_str($postedTLD)."')";
$this->load->view('success/domainfree');
## please register
}
}
}
?>
and two silly views right now: domainexists and domainfree:
domainexists:
<h2>Domain Exists</h2>
domainfree:
<h2>Domain free</h2>
The problem is: when I run the script, there are no errors, but it is properly executing else{} block, but not inputting anything into the database.
I have setup config/autoload to autoload the db lib, like:
$autoload['libraries'] = array('database');
What am I doing wrong here?
You aren’t running the SQL query. Do this.
or you can use simple_query()