Welcome Guest, Not a member yet? Register   Sign In
db->query HELP :(
#5

[eluser]Kenshiro[/eluser]
The only thing i could see wrong with your query is the ID field, as it's an auto field i guess, just leave it out of your query...

Code:
$query = "INSERT INTO ci_images (imagetype, usage, usage_id, size_num, size, name, fullpath, comment) VALUES ( '$data[imagetype]', '$data[usage]', '$data[usage_id]', '$data[size_num]', '$data[size]', '$data[name]', '$data[fullpath]', '$data[comment]')";

$r = $this->db->query($query);

Also numeric data should be treated as numeric, that meane, '$data['usage_id']' should be written $data['usage_id'] (without the quotes), lastly as you are using " (double quotes) to have your array parsed directly i think errors might arise as well, cause $data[imagetype] should actually be $data['imagetype'] or else imagetype is assumed to be a constant or var by php (when it's not).

So i would actually write the query this way :

Code:
$query = 'INSERT INTO ci_images (imagetype, usage, usage_id, size_num, size, name, fullpath, comment) VALUES ( "'.$data[imagetype].'", "'.$data[usage].'", '.$data[usage_id].', '.$data[size_num].', "'.$data[size].'", "'.$data[name].'", "'.$data[fullpath].'", "'.$data[comment].'")';

$r = $this->db->query($query);

//even better if you are building with mysql and don't plan on switching of DB engine anytime soon there is a simple way to write the sql query in an update syntax manner.

$query = 'INSERT INTO ci_images SET imagetype = "'.$data['imagetype'].'", usage = "'.$data['usage'].'", usage_id = '.$data['usage_id'].', size_num = '.$data['usage_id'].', size = "'.$data['size'].'", name = "'.$data['name'].'", fullpath = "'.$data['fullpath'].'", comment = "'.$data['comment'].'"';

$r = $this->db->query($query);

// Or lastly use the Active record way...


Messages In This Thread
db->query HELP :( - by El Forum - 05-04-2010, 05:21 AM
db->query HELP :( - by El Forum - 05-04-2010, 05:43 AM
db->query HELP :( - by El Forum - 05-04-2010, 05:50 AM
db->query HELP :( - by El Forum - 05-04-2010, 07:35 AM
db->query HELP :( - by El Forum - 05-04-2010, 10:56 AM
db->query HELP :( - by El Forum - 05-04-2010, 11:24 AM
db->query HELP :( - by El Forum - 05-04-2010, 01:15 PM
db->query HELP :( - by El Forum - 05-04-2010, 02:50 PM



Theme © iAndrew 2016 - Forum software by © MyBB