Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is this MySQL INSERT not working in CI?
    primarykey
    data
    text
    <p>For some reason this SQL statement is not working. Can anyone tell me why? (This is a Codeigniter site, if that matters)</p> <p>Here is my Model (where my error is pointing me to)</p> <pre><code>public function edit_profile($ID, $field, $new_info) { $sql = "UPDATE users SET ?=? WHERE id=?"; $query = $this-&gt;db-&gt;query($sql, array($field, $new_info, $ID)); // &lt;&lt;&lt;&lt; LINE 42 return $query; } </code></pre> <p>And this is the error I'm getting</p> <pre><code>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 ''first_name'='oooo' WHERE id='151'' at line 1 UPDATE users SET 'first_name'='oooo' WHERE id='151' Filename: /Applications/MAMP/htdocs/MY_SITE/models/member_model.php Line Number: 42 </code></pre> <p>My table is called 'users', and I have a 'first_name' and 'id' column.</p> <p>Ideas?</p> <p><strong>EDIT</strong></p> <p>Just because it seems to come up a bit I want to clarify that the variables I am passing in here have NO QUOTES OR BACKTICKS. They are being added somewhere (and it seems like the ->query method, but I cant imagine that's true? .. dunno though, cause it's my first CI project)</p> <p>Here is the controller that is passing to the model...</p> <pre><code>public function profileEdit() { $ID = $this-&gt;the_user-&gt;id; $field = $this-&gt;input-&gt;post('edit_field') $field = strstr($field,'_edit', true); $new_info = $this-&gt;input-&gt;post('new_info'); $this-&gt;load-&gt;model('Member_model'); if( $this-&gt;Member_model-&gt;edit_profile( $ID, $field, $new_info )){ echo 'success'; } else { echo 'error'; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload