Welcome Guest, Not a member yet? Register   Sign In
Error number: 1048, Problem using the Captcha Helper
#1

[eluser]Unknown[/eluser]
Dear user,

I just tried to implement the captcha helper to a contact formular. The Captcha Helper will be loaded automatically.

Link to Captcha Helper, User Guide

--------------------------------------------------
Step 1: (controller document)
Code:
public function __construct() {
  parent::__construct();
  $this->load->database();
[...]
  $this->load->helper('captcha');
[...]
}

--------------------------------------------------
Step 2: (contact document - default content (if no submit button has been pressed))
Code:
[...]
  <?php
   $vals = array(
    'img_path' => './captcha/',
    'img_url' => 'http://example.com/captcha/'
    );

   $cap = create_captcha($vals);

   $data = array(
    'captcha_time' => $cap['time'],
    'ip_address' => $this->input->ip_address(),
    'word' => $cap['word']
    );

   $query = $this->db->insert_string('captcha', $data);
   $this->db->query($query);

   echo 'Submit the word you see below:';
   echo $cap['image'];
   echo '<input type="text" name="captcha" value="" />';
  ?>
[...]

--------------------------------------------------
Step 3: (contact document - (if a submit has been pressed))
Code:
<?php
if ($this->input->post('contact-submit', TRUE) == true) {
$valid_formular = true;

[...]

// First, delete old captchas
$expiration = time()-7200; // Two hour limit
$this->db->query("DELETE FROM captcha WHERE captcha_time < ".$expiration);

// Then see if a captcha exists:
$sql = "SELECT COUNT(*) AS count FROM captcha WHERE word = ? AND ip_address = ? AND captcha_time > ?";
$binds = array($_POST['captcha'], $this->input->ip_address(), $expiration);
$query = $this->db->query($sql, $binds);
$row = $query->row();

if ($row->count == 0) {
  echo "You must submit the word that appears in the image";
}
}
?&gt;


--------------------------------------
Well, I did everything they told me in the User Guide and I receive following Error Message:
Quote:Error Number: 1048

Column 'captcha_time' cannot be null

INSERT INTO `captcha` (`captcha_time`, `ip_address`, `word`) VALUES (NULL, '127.0.0.1', NULL)

Filename: C:\xampp\htdocs\portal\system\database\DB_driver.php

Line Number: 330

I know there're missing strings but I got no clue how to fix this problem since I copyied everything from the user guide, as I told already.


If you have a link to a page on it my issue been solved already, it's enough. I only found one in this board with the same issue but it didn't help me.. That's why I decided to create a new topic.

With best regards,
Martin
#2

[eluser]vrencianz[/eluser]
The create_captcha() could not create the captcha image using your parameters

Code:
$vals = array(
    'img_path' => './captcha/',
    'img_url' => 'http://example.com/captcha/'
    );

To solve this:

1) make a directory inside codeigniter root name 'captcha' and writeable by all (or only by your web server)
2) change 'example.com' from 'http://example.com/captcha/' to your site (localhost?)




Theme © iAndrew 2016 - Forum software by © MyBB