Updating Multiple Rows in One Table... |
[eluser]fancms[/eluser]
Right now I have this code to update multiple rows of one table, after validation has been run and no errors are found: Code: foreach($_POST as $key=>$val) { Prior to CI I would update multiple rows like so: Code: $db->query("UPDATE tablename SET value = CASE However, when I tried to use this way in CI, I kept getting errors, primarily error 1064, which, from what I was able to determine, is caused by apostrophes not being escaped. I did check that magic_quotes is disabled (it is). I also noticed it was throwing this error on anything I used $this->db->escape on that did *not* have an apostrophe. Anyway, I guess what I want to know is if there is any way to update multiple rows using the second example (or something similar) and still being able to escape the data?
[eluser]tonanbarbarian[/eluser]
I have never had any issues using $this->db->escape. Which database are you connecting to? as for the first method if you want to do it safely try Code: foreach(array_keys($_POST) as $key) {
[eluser]fancms[/eluser]
i am connecting to a mysql database. this is an example of the error i get: Quote:An Error Was Encounteredthis is the syntax around those lines: Code: $configupdate = $this->db->query("UPDATE ".$this->db->dbprefix."settings SET value = CASE Quote:as for the first method if you want to do it safely trythanks, tonanbarbarian - that does help now if i can only figure out a way to reduce the number of queries
[eluser]tonanbarbarian[/eluser]
the problem is that you are confusing the $this->db->escape and $this->db->escape_str If you are using $this->db->escape you do not need to put your own singel quotes around the data escape_str just makes sure that any quotes etc are escaped correctly in the string escape uses escape_str and then puts the quotes around the string as well try this Code: $configupdate = $this->db->query("UPDATE ".$this->db->dbprefix."settings SET value = CASE
|
Welcome Guest, Not a member yet? Register Sign In |