Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8868083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:10:56+00:00 2026-06-14T17:10:56+00:00

For some reason this SQL statement is not working. Can anyone tell me why?

  • 0

For some reason this SQL statement is not working. Can anyone tell me why? (This is a Codeigniter site, if that matters)

Here is my Model (where my error is pointing me to)

public function edit_profile($ID, $field, $new_info)
{
    $sql = "UPDATE users SET ?=? WHERE id=?";
    $query = $this->db->query($sql, array($field, $new_info, $ID)); // <<<< LINE 42
    return $query;
}

And this is the error I’m getting

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

My table is called ‘users’, and I have a ‘first_name’ and ‘id’ column.

Ideas?

EDIT

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)

Here is the controller that is passing to the model…

public function profileEdit()
{
    $ID = $this->the_user->id;
    $field = $this->input->post('edit_field')
    $field = strstr($field,'_edit', true);
    $new_info = $this->input->post('new_info');

    $this->load->model('Member_model');
    if( $this->Member_model->edit_profile( $ID, $field, $new_info )){
        echo 'success';
    }
    else
    {
        echo 'error';
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T17:10:57+00:00Added an answer on June 14, 2026 at 5:10 pm

    i suggest use like this :

    public function edit_profile($ID, $field, $new_info)
    {
        $sql = "UPDATE users SET $field =? WHERE id=?"; # UPDATED (remove $this->db->escape())
        $query = $this->db->query($sql, array($new_info, $ID)); // <<<< LINE 42
        return $query;
    }
    

    if $field is not secured you can use escape functions .
    EDIT :
    $this->db->escape() will add quotes around variable so you will get an error again .

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason this statement is working fine: vms.Where(vm => vm.MessageType == ValidationMessage.EnumValidationMessageType.Warning) But
For some reason this program is saying that 'switch' is not defined. What is
This evaluation in sql doesn't seems to work properly for some reason but i
For some reason this isn't working, am I missing something obvious? RewriteRule ^(.*)infopopup.html$ /acatalog/infopopup.html
For some reason this line of code is giving me quite a problem. struct
For some reason this () character shows up in Firefox 10 randomly throughout my
For some reason this text isn't being centered. #highlightheader { background-color:#006600; color:white; font-size:30px; text-align:center;
For some reason This php script won't echo anything: <?php setcookie(pop,'hi',time()+604800); echo $HTTP_COOKIE_VARS['pop']; ?>
For some reason this function confused me: def protocol(port): return port == 443 and
For Some reason this query doesn't work in SSIS Select IDLOGARCHIVOS, NOMBREARCHIVO, FECHACREACION from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.