How does php modify data in the database according to the specified ID?

Source: Internet
Author: User
How does php modify database data based on the specified ID?
$ Query = mysql_query ('select * FROM wdksm ');
While ($ row = mysql_fetch_assoc ($ query ))
{{
$ Id = $ row ['id'];
Echo 'date: '. $ row ["time"]. '';
Echo 'Department: '. $ row ["bumen"]. '';
Echo 'name: '. $ row ["name"]. '';
Echo 'Title: '. $ row ["zhiwu"].'
';
Echo 'time not punched in: '. $ row ["wdktime"].'
';
Echo 'The reason for not logging in: '. $ row ["wdkyy"].'
';
Echo 'Department owner review: '. $ row ["bmshtime"]. '';
Echo 'approval from the personnel administration department/General Manager: '. $ row ["rsshtime"].'
';
}
Echo '';
Echo'
';
}
$ SQL = 'update wdksm SET
Rsshtime = \ ''. $ _ POST ['test']. '\'
WHERE id = \ ''. $ id .'\'';
Mysql_query ($ SQL );

?>


Reply to discussion (solution)

ID is a number ''?

Can't you execute your update statement? It looks okay.

Update your table name set column name to be changed = value to be changed where id = id you specified

If I click review under each data entry based on the data in the preceding column, the data will be "reviewed" and written to the current data entry, the data currently written is written to the bottom data by default.

Your form is generated in this way.

echo '';
There is no id value in it
Therefore, the submitted data does not contain a unique identification id.

The id in your SQL command is the last id when the list is generated. of course, this is wrong.

In addition, the writing of your SQL commands is weird.
This is better written.
$sql = "UPDATE wdksm SET rsshtime = '$_POST[test]' WHERE id = '$_POST[id]'";

$sql = "UPDATE wdksm SET rsshtime = '$_POST[test]' WHERE id = '$_POST[id]'";
This code cannot be written. how do I select an id and write data to this id without affecting the data of other IDs?

While ($ row = mysql_fetch_assoc ($ query ))
{
$ Id = $ row ['id'];
Echo 'date: '. $ row ["time"]. '';
Echo 'Department: '. $ row ["bumen"]. '';
Echo 'name: '. $ row ["name"]. '';
Echo 'Title: '. $ row ["zhiwu"].'
';
Echo 'time not punched in: '. $ row ["wdktime"].'
';
Echo 'The reason for not logging in: '. $ row ["wdkyy"].'
';
Echo 'Department owner review: '. $ row ["bmshtime"]. '';
Echo 'approval from the personnel administration department/General Manager: '. $ row ["rsshtime"].'
';
Echo '';
Echo'


';
}

While ($ row = mysql_fetch_assoc ($ query ))
{
$ Id = $ row ['id'];
Echo 'date: '. $ row ["time"]. '';
Echo 'Department: '. $ row ["bumen"]. '';
Echo 'name: '. $ row ["name"]. '';
Echo 'Title: '. $ row ["zhiwu"].'
';
Echo 'time not punched in: '. $ row ["wdktime"].'
';
Echo 'The reason for not logging in: '. $ row ["wdkyy"].'
';
Echo 'Department owner review: '. $ row ["bmshtime"]. '';
Echo 'approval from the personnel administration department/General Manager: '. $ row ["rsshtime"].'
';
Echo '';
Echo'


';
}

The eldest brother upstairs can't add the code according to your line.

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.