Welcome Guest, Not a member yet? Register   Sign In
problem with ajax and sql insert
#1

[eluser]andygo[/eluser]
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Insertquery_model extends CI_Model
{

function __construct()
{
  parent::__construct();
}



function insertquery($query_terms, $table)
{

$dsn = $this->session->userdata('dsn');
$DB1 = $this->load->database($dsn, TRUE);

$fields = '';
$binding = '';

  foreach($query_terms as $key => $value)
  {
  $values[] = $value;
  $fields .= $key.",";
  $binding .= '?,';
  }

//remove the last comma
$fields = rtrim($fields,',');
$binding = rtrim($binding,',');

$sql = "INSERT INTO $table ($fields) VALUES ($binding)";
$DB1->query($sql, $values);
//return $DB1->last_query();
return $DB1->insert_id();
}//end method

}//end class

This works normally. For example when I submit a form with userdata, the data is inserted into the database.

However when I do an ajax call the sql query does not initiate.
I have tested each peice of information by returning it to the ajax function and echo-ing to the screen to make sure all the info is going through cleanly. Besides, the array $query_terms is constructed the same way (and by the same code) as it is when i submit the form in the normal way.

So, my question is:
Is there something I am missing when trying to use a model from an ajax call?

Thanks :-)
#2

[eluser]andygo[/eluser]
ok
sorry
feel very silly :-)

i had a database field that doesnt accept null values.....
one of the values in the $query_terms array was null
[embarassed smiley goes here]




Theme © iAndrew 2016 - Forum software by © MyBB