CodeIgniter Forums
getting a syntax error from mysql when run through $this->db->query(...) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: getting a syntax error from mysql when run through $this->db->query(...) (/showthread.php?tid=48435)



getting a syntax error from mysql when run through $this->db->query(...) - El Forum - 01-16-2012

[eluser]Unknown[/eluser]
I'm getting a syntax error when I run a query through $this->db->query().
However, I don't get the error when I run it directly in mysql.

Any help would be appreciated.

here is the code

Code:
$name = $this->input->post('name');
  $email = $this->input->post('email');
  $password = $this->input->post('password');

  $sql = "set @salt = floor(rand() * 0xFFFFFFFF);"
   .  "set @hash = sha1(concat('$password',@salt));"
   .  "insert into accounts(`name`, `email`, `password_hash`, `password_salt`, `date_created`) "
   .  "values ('$name', '$email', @hash, @salt, now());";
    
  if($this->db->query($sql)) return $this->try_login();
  
  return $this->db->_error_message();