Search code examples
phpmysqlcodeignitersql-insert

CodeIgniter not correctly performing a sql query


In Ci I'm getting the following error:

A Database Error Occurred

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '', '1f37540fc54292b018a9e993da38cb5647dc5587', NOW(), '0')' at line 1

INSERT INTO users (userpid, Email, Password, dateTimeRegistered, isLeader) VALUES ('147344f0e33367f9e6', erf', '1f37540fc54292b018a9e993da38cb5647dc5587', NOW(), '0')

Filename: C:\Workspace\htdocs\Misc-2\DruvlaCi-1\system\database\DB_driver.php

Line Number: 330

But everything seems to be right in the SQL query. Below is my query, any thoughts?

$query = $this->db->query("INSERT IGNORE INTO users (userpid, Email, Password, dateTimeRegistered, isLeader) VALUES ('{$idgen}', {$postedEmail}', '{$hashedPass}', NOW(), '0')");

Solution

  • You're forgetting the opening single quote for the email column

    Try this instead

    $query = $this->db->query("INSERT IGNORE INTO users (userpid, Email, Password, dateTimeRegistered, isLeader) VALUES ('{$idgen}', '{$postedEmail}', '{$hashedPass}', NOW(), '0')");