PHP VAØ DATABASE
9-3
COMPUTER LEARNING CENTER
WWW.HUUKHANG.COM
Hình 9-1: Theâm maåu tin
Ñeå laøm ñieàu naøy, tröôùc tieân baïn khai baùo trang them.php, trong ñoù khai baùo ñoaïn javascript ñeå
kieåm tra döõ lieäu nhaäp nhö sau:
<SCRIPT language=JavaScript>
function
checkInput()
{
if (document.frmPHP.txtID.value=="")
{
alert("Invalid ID, Please enter ID");
document.frmPHP.txtID.focus();
return
false;
}
if
(document.frmPHP.txtName.value=="")
{
alert("Please enter Name");
document.frmPHP.txtName.focus();
return
false;
}
return
true;
}
</script>
Keá ñeán khai baùo theå form vaø hai theû input laïi text yeâu caàu ngöôøi söû duïng nnaäp ID vaø Name nhö
sau:
<form name="frmPHP" method="post"
action="doinsert.php"
onsubmit="return checkInput();">
<tr>
<td align="left" class="content-sm"><b>
Please enter ID and Name
</b></td>
</tr>
<tr>
<td align="left" >ID:</td>
</tr>
<tr>
<td align="left">
<input type="text" name="txtID"
size="25"
maxlength="3"
class="textbox">
</td>