dongtaigan1594 2010-10-21 17:37
浏览 37
已采纳

从CodeIgniter更新MySQL语句

I'm having a problem with this query for some reason:

$this->db->query("UPDATE schools SET name = '$name', pop = '$pop', details = '$details', numteachers = '$numteachers', recess = '$recess', equipment = '$equipment' WHERE id = '$schoolid'");
echo $this->db->affected_rows(); 

For some reason affected_rows prints 0 but there's no errors with the query. When I look in the database the row id has not been affected. I escape all the inputs before the query like this:

$name = mysql_real_escape_string($_POST["schoolname"]);

With all of the inputs, an example query with real inputs looks like this before its executed:

UPDATE schools SET name = 'Jefferson County Public School', pop = '2,345', details = 'Lorem Ipsum is simply dummy text of the and typesetting industry.', numteachers = '2 Te', recess = '40 mins', equipment = 'Gym, Climbing Frame, Goal Posts, Track' WHERE id = '1'

All of the columns are already populated under row id 1, this is just new data. id is an int, primary key and auto_incrementing.

Any advice would help, thank you!

  • 写回答

2条回答 默认 最新

  • doufu8127 2010-10-21 18:58
    关注

    Are you sure that the resulting query is actually what's generated, or did you just insert some data? Check to make sure that your ID is actually the ID of the row that you want to update... it may be null, or something unexpected.

    ;)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?