Tạo database

:
<?php $conn = mysql_connect("localhost","root", "") or die (mysql_error()); $string = "create database my_other_db"; mysql_query($string) or die(mysql_error()); if($string) { echo " ?ã t?o ???c database"; } ?>

Tạo table:

<?php $link = mysql_connect("localhost", "root", ""); if ($link) { echo "kết nối được tới MySQL"; } mysql_select_db("my_other_db", $link) or die(mysql_error()); $query = "create table my_table (id int primary key, name text)"; mysql_query($query) or die(mysql_error()); mysql_close($link); ?>

Sửa dử liệu bằng form: sua.php và doupdate.php
<html> <head> <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> </head> <body> <form name="frmPHP" method="post"

echo "<br>".php <?php echo $txtID. echo $txtName. $link = mysql_connect("localhost". "root".action="doupdate. if ($link) { echo "kết nối được tới MySQL". echo "<br>". } . </td> </tr> <tr> <td align="left" ><p>Name:</p> </td> </tr> <tr> <td align="left" > <input type="text" name="txtName" size="25" maxlength="50" class="textbox"> </td> </tr> <tr> <td align="left" valign="top"> <p> <input name="submit" type="submit" class="button" value="Submit"> <input name="reset" type="reset" class="button" value="Reset"> </p> </td> </tr> </form> </body> </html> Doupdate. "").php" onsubmit="return checkInput()."> <tr> <td align="left" class="content-sm"><p><b> Please enter ID and Name</b></p> </td> </tr> <tr> <td align="left" >ID:</td> </tr> <p> <input type="text" name="txtID" size="25" maxlength="3" class="textbox"> </p> <tr> <td align="left">&nbsp.

mysql_close($link).frmPHP. ?> So mau tin cap nhat <?php echo $affectrow ?> Thêm vào csdl gồm 2 form : nhap. $query = "Update my_table set name ='$txtName' where id ='$txtID'". Please enter ID").txtID. document. mysql_select_db("my_other_db".php và doinsert. $affectrow=0.php" onsubmit="return checkInput().focus().frmPHP. $link) or die(mysql_error()). return false. return false."> <tr> <td align="left" class="content-sm"><p><b> Please enter ID and Name</b></p> </td> </tr> <tr> <td align="left" >ID:</td> </tr> <p> <input type="text" name="txtID" size="25" maxlength="3" class="textbox"> </p> <tr> . } return true.value=="") { alert("Please enter Name").frmPHP. if($result) $affectrow=mysql_affected_rows(). $result=mysql_query($query) or die(mysql_error()).txtName. document.echo "<br>".value=="") { alert("Invalid ID.txtName. } if (document.focus().php <html> <head> <SCRIPT language=JavaScript> function checkInput() { if(document.txtID.frmPHP. } </script> </head> <body> <form name="frmPHP" method="post" action="doinsert.

$query = "insert into my_table (id. mysql_close($link). echo "<br>". "root".name) values ('$txtID'.php <html> <head> <SCRIPT language=JavaScript> function checkInput() { . mysql_query($query) or die(mysql_error()). if ($link) { echo "kết nối được tới MySQL".php ketquaxoa. ?> Xóa một đối tượng gồm 2 form : xoabangform. } echo "<br>". $link) or die(mysql_error()). "").<td align="left">&nbsp.php <?php echo $txtID. echo $txtName.'$txtName')". $link = mysql_connect("localhost". mysql_select_db("my_other_db". </td> </tr> <tr> <td align="left" ><p>Name:</p> </td> </tr> <tr> <td align="left" > <input type="text" name="txtName" size="25" maxlength="50" class="textbox"> </td> </tr> <tr> <td align="left" valign="top"> <p> <input name="submit" type="submit" class="button" value="Submit"> <input name="reset" type="reset" class="button" value="Reset"> </p> </td> </tr> </form> </body> </html> Doinsert. echo "<br>".

document.txtID.if (document.value=="") { alert("Invalid ID. } </script> </head> <body> <form name="frmPHP" method="post" action="ketquaxoa. Please enter ID"). .frmPHP. } return true.frmPHP. </td> </tr> <td align="left" valign="top"> <p> <input name="submit" type="submit" class="button" value="Submit"> <input name="reset" type="reset" class="button" value="Reset"> </p> </td> </tr> </form> </body> </html> Ketquaxoa.focus(). if ($link) { echo "ket noi duoc toi MySQL". "root". $link = mysql_connect("localhost". $link) or die(mysql_error()). ""). mysql_select_db("my_other_db".$txtID. echo "<br>". return false.php" onsubmit="return checkInput()."> <tr> <td align="left" class="content-sm"><p><b> Please enter ID and Name</b></p> </td> </tr> <tr> <td align="left" >ID:</td> </tr> <p> <input type="text" name="txtID" size="25" maxlength="3" class="textbox"> </p> <tr> <td align="left">&nbsp. } echo "<br>".txtID.php <?php echo "da xoa ".

} ?> <h2>View My Table!</h2> <?php mysql_select_db("my_other_db".php <?php $link = mysql_connect("localhost". } mysql_select_db("my_other_db". echo "<b>Tensp:</b>".'entry one')". $affectrow=0. } ?> Them bang mot file php them.$query = "Delete from my_table where id ='$txtID'".php <?php $link = mysql_connect("localhost". "root". "root". $result = mysql_query("select * from my_table") or die (mysql_error()). echo $row["name"]. while ($row = mysql_fetch_array($result)) { echo "<b>Masp:</b>". ""). mysql_close($link). if ($link) { echo "kết nối được tới MySQL". echo "<br>". name ) values ('001'. mysql_close($link). $query = "insert into my_table (id. mysql_query($query) or die(mysql_error()). echo "<br>". echo $row["id"]. ?> . ""). $link) or die(mysql_error()). if($result) $affectrow=mysql_affected_rows(). ?> Xem bảng xem. $link) or die(mysql_error()). if ($link) { echo "kết nối được tới MySQL". $result=mysql_query($query) or die(mysql_error()). echo "<br>".

Sign up to vote on this title
UsefulNot useful