• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cannot insert into database, no error shows

This has been bothering me for days now and no one else seems to have this problem on the entire web.
It's a database problem. Insert does not seem to work, no matter what I try (active record or not).
It's just submitting a form and inserting its values but nothing happens...

This is the class that's supposed to do the job.

if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class RegisterAction {
private $ci;
function __construct(){
$this->ci =& get_instance();
public function doRegister($profile, $name, $email, $password) {

$uid= $name.time();

// This doesn't work :-( :

// $insertquery = "INSERT INTO user (uid, uname,uemail,upass, uprofile) VALUES (".$this->ci->db->escape($uid).", ".$this->ci->db->escape($name).",".$this->ci->db->escape($email).",".$this->ci->db->escape($password).",".$this->ci->db->escape($profile).")";
// var_dump($insertquery);
// error_reporting(E_ALL);
//ini_set('display_errors', '1');
//echo "Affected rows: ".$this->ci->db->affected_rows();

//Let's try active record
$data = array(
'uid' => $this->ci->db->escape($uid),
'uname' => $this->ci->db->escape($name),
'uemail' => $this->ci->db->escape($email),
'upass' => $this->ci->db->escape($password),
'uprofile' => $this->ci->db->escape($profile)

$this->ci->db->insert('user', $data);

if($this->ci->db->affected_rows() > 0)
echo 'Row succesfully inserted, at least that\'s what I think';

else {
echo 'Something is wrong. But we don\'t know what for some days now, do we?...';
} //end function

(Notice I also have to get the CI instance "by force" as $this does not get it.)
It generates the right query though because if I enter the var_dumped query in phpmyadmin it works.

Is database debugging turned on so it will show errors?
Is this a library or controller? (its written like a library)
When using active record, you don't need (and shouldn't) escape variables. AR automatically does that so you are escaping them 2x which might be producing extra quote marks in the sql.
What is the actual query that gets run? (use echo $this->db->last_query())
Please use code tags when posting code Smile

Also, how are you passing the parameters to this method:
doRegister($profile, $name, $email, $password)
and are you sure they are being passed correctly?

Dear CroNix,

Thanks for your quick reply!
I actually had the $db['default']['db_debug'] variable set to false and did not see the error (for some people it looks like the solution is to try and hide the error message :-) at least that's what some forum posts said elsewhere but I realized that this is indeed an error that should be taken seriously).

So it is the good old

Unable to connect to your database server using the provided settings.

Filename: core/Loader.php

Line Number: 346

I suspect it might be my host name. Admin stuff is my weak point so I don't exactly know what a mysql hostname usually looks like. Some people say it's simply localhost, my service provider help says it's simply sql, phpmyadmin says the hostname variable is rb02-gm...or is it some combination of these?
Can we perhaps get some more detailed error message out of mysql?

I dunno. To answer your questions: yes, it's a library class called from a controller.
It gets called like this:

public function doRegister() {
        if (strcmp($profile, 'jobseeker')==0) {
         if (strcmp($profile, 'employer')==0) {
        $CI =& get_instance();
       $CI->registeraction->doRegister($profile, $uname, $uemail, $upass);
       echo 'Regpages controller\'s doregister method was called';

I finally stumbled upon the solution in another thread:
$db['default']['pconnect'] = FALSE;

Well, well, who would have thought? :-)
Anyway, this info could be included in the manual or troubleshooting or something.

Anyway, thanks for your effort! I might come back since I'm actually writing my thesis about a CodeIgniter based website.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.