PHP VAØ DATABASE
9-5
COMPUTER LEARNING CENTER
WWW.HUUKHANG.COM
$affectrow=mysql_affected_rows();
mysql_close($link);
?>
So mau tin cap nhat <?= $affectrow?>
</BODY>
</HTML>
Löu yù raèng, ñeå bieát soá maåu tin ñaõ thöïc thi bôûi phaùt bieåu SQL baïn söû duïng haøm
mysql_affected_rows.
if($result)
$affectrow=mysql_affected_rows();
Töông töï nhö treân, baïn coù theå thieát keá form cho pheùp ngöôøi söû duïng caäp nhaät döõ lieäu baèng caùch
thieát keá form yeâu caàu ngöôøi söû duïng nhaäp maõ vaø teân caäp nhaän.
Tröôùc tieân thieát keá from cho pheùp nhaäp döõ lieäu ñeå caäp nhaät nhö ví duï trang capnhat.php, sau
khi hoïc phaàn truy vaán xong, thaqy vì nhaäp maõ baïn cho pheùp ngöôøi söû duïng choïn trong danh saùch ñaõ
coù nhö hình 9-2.
Hình 9-2: Caäp nhaät döõ lieäu
Sau khi ngöôøi söû duïng nhaán nuùt submit, trang doupdate.php seõ trieäu goïi, keát quaû traû veà 1 hay 0
maåu tin.
<HTML>
<HEAD>
<TITLE>::Welcome to PHP and mySQL</TITLE>
</HEAD>
<BODY>
<h3>Cap nhat mau tin</h3>
<?php
$affectrow=0;
require("dbcon.php");
$sql="update tblships set ShipName='";
$sql .=$txtName."' where ShipID='".$txtID."'";
$result
=
mysql_query($sql,$link);
if($result)
$affectrow=mysql_affected_rows();
mysql_close($link);
?>