Thinkphp failed to modify database data

Source: Internet
Author: User
{Code...} my modified function code is as above, and the value of the $ room_info object is printed. it is indeed modified, but why does the database data remain unchanged after execution. Why?
Public function update () {$ room = M ('Room '); // $ room_id = $ _ GET ['room _ id']; $ room_id = $ _ POST ['room _ id']; $ roominfo ['room _ id'] = $ _ POST ['room _ id']; $ roominfo ['room _ type'] =_ _ POST ['room _ type']; $ roominfo ['room _ status'] = $ _ POST ['room _ status']; $ room _ area] = $ _ POST ['room _ area ']; $ roominfo ['room _ cost'] = $ _ POST ['room _ cost']; $ roominfo ['description'] = $ _ POST ['description']; print_r ($ roominfo); // $ room-> where ("room_id = $ room_id")-> save ($ roominfo ); echo "script" alert ('modified successfully') script "; // $ this-> redirect (" showRoom ");}

My modified function code is as follows: the value of the $ room_info object is printed and indeed modified. But why does the database data remain unchanged after execution. Why?

Reply content:
Public function update () {$ room = M ('Room '); // $ room_id = $ _ GET ['room _ id']; $ room_id = $ _ POST ['room _ id']; $ roominfo ['room _ id'] = $ _ POST ['room _ id']; $ roominfo ['room _ type'] =_ _ POST ['room _ type']; $ roominfo ['room _ status'] = $ _ POST ['room _ status']; $ room _ area] = $ _ POST ['room _ area ']; $ roominfo ['room _ cost'] = $ _ POST ['room _ cost']; $ roominfo ['description'] = $ _ POST ['description']; print_r ($ roominfo); // $ room-> where ("room_id = $ room_id")-> save ($ roominfo ); echo "script" alert ('modified successfully') script "; // $ this-> redirect (" showRoom ");}

My modified function code is as follows: the value of the $ room_info object is printed and indeed modified. But why does the database data remain unchanged after execution. Why?

// $ Room-> where ("room_id = $ room_id")-> save ($ roominfo );

Do you want to remove the annotator...

In addition: "room_id = $ room_id", the landlord can Baidu SQL injection.

M ()-> getLastsql ()

It should bethinkphp.

  1. Do not directly use$_POSTOr use$_GetTo preventSQL injection, Should be usedIFunction.

  2. SQL debugging should be used$obj->getLastsql()Method.

  3. Output objectdumpFunction.

If the code is okay, it may also be a problem with your database. for example, if your account does not have the write permission, you can read the database and cannot perform the update operation. First, check for any problems.

  1. Print M ()-> getLastsql () if possible ()

  2. If your room_id is the primary key of the table, you can use the following code:

    $roominfo['room_id']=$_POST['room_id'];$roominfo['room_type']=$_POST['room_type'];$roominfo['room_status']=$_POST['room_status'];$roominfo['room_area']=$_POST['room_area'];$roominfo['room_cost']=$_POST['room_cost'];$roominfo['description']=$_POST['description'];$room->save($roominfo);

$ Room-> where ("room_id =". $ room_id)-> save ($ roominfo );

Let's try again.

Add this sentence under $ room_id: $ roominfo = $ room-> getByID ($ room_id );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.