ลองเขียนเล่นนะๆ ผิดไง ขออภันลองเอาไปดัดแปลงเอานะ
อันนี้ตั้งชื่อว่า editdata.php
<?
$host="localhost";
$user="fff";
$password="fff";
$db="fff";
$conn = mysql_connect($host,$user,$password) or die ("Error");
$strcommand="select * from movie ORDER BY id DESC LIMIT 10";
$result = mysql_db_query($db,$strcommand,$conn);
echo "<table border=1>";
while( $row= mysql_fetch_array($result)){
echo "
<tr>
<td><a href=\"editform.php?id={$row['id']}\" > {$row['id']} </a> </td>
<td> {$row['nameen']}</td>
<td> {$row['nameth']}</td>
<td> {$row['code']}</td>
</tr>
";
}
echo "</table>";
?>
อันนี้ตั้งชื่อว่า editform.php
<?
if (isset($_POST['txtid'])){
$id = $_POST['txtid'];
$prename = $_POST['txtnameen'];
$name = $_POST['txtnameth'];
$lname = $_POST['txtcode'];
$host="localhost";
$user="fff";
$password="fff";
$db="fff";
$conn = mysql_connect($host,$user,$password) or die ("Error");
$strcommand = "update movie set nameen='$prename',nameth ='$name', code='$lname' where id='$id'";
$result = mysql_db_query($db,$strcommand,$conn);
if ($result){
echo "Update Complete";
}else{
echo "Can not complete";
}
mysql_close($conn);
}else{
$host="localhost";
$user="fff";
$password="fff";
$db="ffff";
$conn = mysql_connect($host,$user,$password) or die ("Error");
$strcommand="select * from movie where id = '$id'";
$result = mysql_db_query($db,$strcommand,$conn);
$row= mysql_fetch_array($result);
echo "
<form name=\"form1\" method=\"post\" action=\"{$_SERVER['PHP_SELF']}\">
<table width=\"200\" border=\"1\" align=\"center\">
<tr>
<td>id</td>
<td><input name=\"txtid\" type=\"text\" id=\"txtid\" value=\"{$row['id']}\"></td>
</tr>
<tr>
<td>prename</td>
<td><input name=\"txtnameen\" type=\"text\" id=\"txtnameen\" value=\"{$row['nameen']}\"></td>
</tr>
<tr>
<td>name</td>
<td><input name=\"txtnameth\" type=\"text\" id=\"txtnameth\" value=\"{$row['nameth']}\"></td>
</tr>
<tr>
<td>lname</td>
<td><input name=\"txtcode\" type=\"text\" id=\"txtcode\" value=\"{$row['code']}\"></td>
</tr>
<tr>
<td><input type=\"submit\" name=\"Submit\" value=\"Submit\"></td>
<td><input type=\"reset\" name=\"Submit2\" value=\"Reset\"></td>
</tr>
</table>
</form>
";
mysql_close($conn);
}
?>