PHP implementation of the MySQL update record code _php basis

Source: Internet
Author: User

First comb the operation idea:

List all data
Select the data record you want to modify to enter the editable state.
Submit Modification Results Complete modification
The data in the database is listed first, and a modify is added before each record, so that the user can select the records that they want to modify view.php.
Copy Code code as follows:

<?php
$link =mysql_connect ("localhost", "root", "admin password");
mysql_select_db ("Infosystem", $link);
$q = "SELECT * from Info";
mysql_query ("SET NAMES GB2312");
$rs = mysql_query ($q, $link);

echo "<table>";
echo "<tr><td> department name </td><td> employee name &LT;/TD&GT;&LT;TD&GT;PC name </td></tr>";
while ($row = Mysql_fetch_row ($rs)) echo "<tr><td><a href= ' modify_do.php?id= $row [0] ' >modify</a ></td><td> $row [1]</td><td> $row [2]</td><td> $row [3]</td><td>$ row[4]</td><td> $row [5]</td><td> $row [6]</td><td> $row [7]</td><td > $row [8]</td><td> $row [9]</td><td> $row [10]</td><td> $row [11]</td> <td> $row [12]</td><td> $row [13]</td></tr> ";
echo "</table>";
?>



When the user clicks Modify, enter the editable state of the corresponding record modify_do.php:

Copy Code code as follows:

<?php

$link =mysql_connect ("localhost", "root", "admin password");
if (! $link) {die ("error");}
echo "Connect MySQL successfully";
mysql_select_db ("Infosystem", $link);
$del _id=$_get["id"];
$q = "SELECT * from info where id= $del _id";

mysql_query ("SET NAMES GB2312"); Code Conversion
$rs = mysql_query ($q, $link);
if (! $rs) {die ("No results Displayed");}
?>

<body>

<form action= "modify_finish.php" method= "POST" >
<?php

echo "<input type= ' text ' size=25 name= ' id ' value= ' $del _id ' >";

while ($row = Mysql_fetch_object ($rs)) echo "<input type= ' text ' size=25 name= ' ename ' value= ' $row->ename ' >";

Mysql_close ($link); Closing datasets

?>

<input type= "Submit" Name= "submitted" value= "Submit" >
</form>
</body>

Finally, process the submit data modify_finish.php:

Copy Code code as follows:

<?php

$link =mysql_connect ("localhost", "root", "admin password");
if (! $link) {die ("error");}
echo "Connect MySQL successfully";
mysql_select_db ("Infosystem", $link);

mysql_query ("SET NAMES GB2312");

$rs = mysql_query ($q, $link);
$row = Mysql_fetch_object ($RS);
$exec = "Update info set ename= '". $_post[' ename '. "' where id= '. $_post[' id ']." "; Modify the data and add the last update time

echo "Modify success!"

Mysql_close ($link); Closing datasets

?>

Author: Sunec
Original download: Cenus Blog
All rights reserved. Reprint must be linked to the form of the author and the original source and this statement.

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.