Please help me check my code especially change_form.php
here's my code
update_form.php
<?php
$con = mysql_connect("localhost","root","");
mysql_select_db("exercise",$con);
$query = mysql_query("select * from test_mysql",$con);
$num = mysql_num_rows($query);
echo "<center>Show database data</center>";
echo "<br>";
echo "Database data : $num";
while($num =mysql_fetch_array($query))
{
echo "<br>";
echo $num[0];
echo "<br>";
echo "Name : ";
echo $num[1];
echo "<br>";
echo "Lastname : ";
echo $num[2];
echo "<br>";
echo "Email : ";
echo $num[3];
echo "<br>";
echo "Homepage :
";
echo $num[4];
echo "<br><a href=change_form.php?id=$num[0]>edit</a>";
echo "<br>";
}
?>
change_form.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
</head>
<body>
<?
$con=mysql_connect("localhost","root","");
mysql_select_db("exercise",$con);
$query=mysql_query("select * from test_mysql where id='$id'",$con);
while ($row = mysql_fetch_array($query))
{
?>
<form method="post" action="change_record.php">
Name : <input type="text" name="nama" value="<?php echo $row[1] ?>"/><br/>
lastname : <input type="text" name="lastname" value="<?php echo $row[2] ?>"/><br/>
email : <input type="text" name="email" value="<?php echo $row[3] ?>"/><br/>
<input type="submit" name="submit" value="update"/>
<input type="hidden" name="id" value="$row[0]"/>
</form>
<?
}
?>
</body>
</html>
change_record.php
<?php
$con = mysql_connect("localhost","root","");
mysql_select_db("exercise",$con);
$query = mysql_query("update test_mysql set id='$id',name='$name', lastname='$lastname', email = '$email' where id='$id'");
echo "Data with id = $id has been updated";
?>
any suggestion is much appreciated, thanks