i do believe my code in update is wrong because saving it is working but having trouble with the "Edit". help anyone?
<?php
include 'conn.php';
$flag=$_GET["flag"];
if ($flag=="1")
{
$id = $_GET["id"];
$lname = $_GET["lname"];
$fname = $_GET["fname"];
$mname = $_GET["mname"];
$age = $_GET["age"];
$sex = $_GET["sex"];
$course = $_GET["course"];
$edit = mysql_query( "UPDATE newbase2 SET lname = '".$lname."', fname = '".$fname."', mname = '".$mname."', age='".$age.", 'gender = '".$txtgender."',
course = '".$course."' WHERE id = '$id' ");
$nres = mysql_query($edit);
if(!$nres) {
echo " Failed to edit: ".mysql_error();
} else {
echo " Editing successful";
}
}
if ($flag=="2")
{
$id = $_POST["id"];
$lname = $_POST["lname"];
$fname = $_POST["fname"];
$mname = $_POST["mname"];
$age = $_POST["age"];
$sex = $_POST["sex"];
$course = $_POST["course"];
$ans = "INSERT INTO newbase2 VALUES ('$id','$lname', '$fname', '$mname' , '$age' , '$sex', '$course')";
$result = mysql_query($ans);
if($result!="")
{
echo "<br>Saving Successful";
}
else
{
echo "<br>Failed". mysql_error();
}
}
?>
<html>
<body>
<form method = "post" action = "newedit.php?flag=2">
<pre>
<font size = 5><b>EDITING INFO</b></font>
<b>NAME:</b> <input type = "text" name = "lname" size = "25" maxlength = "20" value = "<?php echo $lname; ?>"> <input type = "text" name = "fname" size =
"25" maxlength = "20" value = "<?php echo $fname; ?>"> <input type = "text" name = "mname" size = "3" maxlength = "3" value = "<?php echo $mname; ?>">
Lastname Firstname Middle
<b>AGE: </b><input type = "text" name = "age" size = "3" maxlength = "3" value = "<?php echo $age; ?>">
<b>SEX: </b><input type = "radio" name = "sex" value = "M"> MALE <input type = "radio" name = "sex" value = "F"> FEMALE
<table>
<b>COURSE:</b> <tr><td><input type = "radio" name = "course" value = "CBA">CBA</td><td><input type = "radio" name = "course" value = "CEA">CEA</td><td><input
type = "radio" name = "course" value = "CICT">CICT</td></tr><tr><td><input type = "radio" name = "course" value = "CAS">CAS</td><td><input type = "radio"
name = "course" value = "CHM">CHM</td><td><input type = "radio" name = "course" value = "CON">CON</td></tr>
</table>
<input type = "submit" name = "submit" value = "SAVE"><input type = "reset" name = "clear" value = "CANCEL">
</form>
</pre>
<?php
$result2 = mysql_query("SELECT * FROM newbase2") or die("Error: " . mysql_error());
echo '<table border ="1">';
echo '<th>ACTION</th><th>ID</th><th>NAME</th><th>AGE</th><th>SEX</th><th>COURSE</th>';
if (count($result2)>0)
{
while ($a = mysql_fetch_array($result2))
{
echo "<tr>";
echo "<td><a href=\"newedit.php?id=".$a["id"]."&flag=1\"> Edit </a></td>";
echo "<td>".$a["id"]."</td>";
echo "<td>".$a["lname"].", ".$a["fname"]." ".$a["mname"].".</td>";
echo "<td>".$a["age"]."</td>";
echo "<td>".$a["sex"]."</td>";
echo "<td>".$a["course"]."</td>";
echo "</tr>";
}
}
echo "</table>";
?>
</body>
</html>