Welcome Guest, Not a member yet? Register   Sign In
Script problem
#1

[eluser]macleodjb[/eluser]
Hi guys, i have this upload script that i've created and i'm having a problem with it and don't know why. I've checked all the keys to see if they are incorrect and they are all fine.

Code:
function update_company($id) {
        $company_name = htmlspecialchars($this->input->post('company_name'));
        $company_city = htmlspecialchars($this->input->post('company_city'));
        $company_bio = htmlspecialchars(trim($this->input->post('company_bio')));
        $update_company = "UPDATE `user_company` SET"
                . " `company_name` = '".$company_name. "',"
                . " `company_city` = '".$company_city. "',"
                . " `company_state` = '".$this->input->post('company_state'). "',"
                . " `company_industry` = '".$this->input->post('company_industry'). "',"
                . " `company_years` = '".$this->input->post('company_years'). "',"
                . " `show_in_search` = '".$this->input->post('show_in_search'). "',"
                . " `company_bio` = '".$company_bio. "' WHERE (`user_id` = '".$id."')";
        $updated = $this->db->affected_rows($update_company);
            if($updated > 0) {
            return true;
            } else {
            return false;
            }
    }

my problem is that it will show that the information has been updated successfully, but when you go to the database it hasnt' changed. Is there a problem with using the post variables nested within htmlspecialchars() function? or is there another problem with this?
#2

[eluser]TheFuzzy0ne[/eluser]
You're not actually updating the data. You're just checking for affected rows.

You'll need to use $this->db->query() to run the query, and then $this->db->affected_rows() to get the affected rows. $this->db->affected_rows() doesn't accept any parameters.

Hope this helps.
#3

[eluser]macleodjb[/eluser]
Thanks for that.
#4

[eluser]TheFuzzy0ne[/eluser]
Oh, and in case you're wondering, $this->db->affected_rows() is passing back the number of affected rows from the last database query. Smile

Code:
function update_company($id) {
    $company_name = htmlspecialchars($this->input->post('company_name'));
    $company_city = htmlspecialchars($this->input->post('company_city'));
    $company_bio = htmlspecialchars(trim($this->input->post('company_bio')));
    $update_company = "UPDATE `user_company` SET"
        . " `company_name` = '".$company_name. "',"
        . " `company_city` = '".$company_city. "',"
        . " `company_state` = '".$this->input->post('company_state'). "',"
        . " `company_industry` = '".$this->input->post('company_industry'). "',"
        . " `company_years` = '".$this->input->post('company_years'). "',"
        . " `show_in_search` = '".$this->input->post('show_in_search'). "',"
        . " `company_bio` = '".$company_bio. "' WHERE (`user_id` = '".$id."')";
    $this->db->query($update_company); /* --The missing statement-- */
    $updated = $this->db->affected_rows($update_company);
    if($updated > 0) {
        return true;
    } else {
        return false;
    }
}
The above code is untested.
#5

[eluser]macleodjb[/eluser]
thanks again, it's hard looking at too much code for too long. it seems the little things slip past you.
#6

[eluser]TheFuzzy0ne[/eluser]
I agree. A pair of fresh eyes never hurts. You wouldn't believe how much pain some silly little typos have caused me. For example, typing:

Code:
if ($something = TRUE)

// instead of

if ($something == TRUE)

Hehe.




Theme © iAndrew 2016 - Forum software by © MyBB