Thanks Bastien.
Below is the full code for the page i'm working on. I've just cracked the problem - not been able to validate the form with javascript before sending the form's data with PHP to a DB table.
I only have one problem left, which I would really appreciate it if you could help me on:
1) When the page loads, the PHP writes "No" immeadiately to the page before the submit button is clicked.
Many thanks!
Sean
<html>
<head>
<title>Update a Player</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<script language="Javascript" type="text/javascript">
function validForm(player_update) {
if (player_update.id.value == "") {
alert("Please enter the player's ID")
player_update.id.focus()
return false
}
if (player_update.nationality.value == "") {
alert("Please enter the player's Nationality")
player_update.nationality.focus()
return false
}
return true
}
</script>
<?php
// the text below inserts the form data into the player1 table
$sql = "INSERT INTO player1 (id, name, surname, age, value, experience, leadership, form, position, rating, injured, nationality)
VALUES ('$id', '$name', '$surname', '$age', '$value', '$experience', '$leadership', '$form', '$position', '$rating', '$injured', '$nationality')";
$result = mysql_query($sql, $conn);
if ($result) {
$message = "thanks";
}
else {
$message = "no";
};
print $message;
mysql_close($conn);
?>
<table width="648" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="395"><p>Update a Player's Details</p>
<form name="player_update" method="post" action="update_player.php" onsubmit="return validForm(this)">
<br>
<table width="648" border="1" cellspacing="0" cellpadding="0">
<tr>
<td width="97">ID</td>
<td width="545"><input type="text" name="id"></td>
</tr>
<tr>
<td>Name</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td>Surname</td>
<td><input type="text" name="surname"></td>
</tr>
<tr>
<td>Age</td>
<td><input type="text" name="age"></td>
</tr>
<tr>
<td>Value</td>
<td><input type="text" name="value"></td>
</tr>
<tr>
<td>Experience</td>
<td><input type="text" name="experience"></td>
</tr>
<tr>
<td>Leadership</td>
<td><input type="text" name="leadership"></td>
</tr>
<tr>
<td>Form</td>
<td><input type="text" name="form"></td>
</tr>
<tr>
<td>Position</td>
<td><input type="text" name="position"></td>
</tr>
<tr>
<td>Rating</td>
<td><input type="text" name="rating"></td>
</tr>
<tr>
<td>Injured</td>
<td><input type="text" name="injured"></td>
</tr>
<tr>
<td>Nationality</td>
<td><input type="text" name="nationality"></td>
</tr>
</table>
<input type="submit" name="Submit" value="Submit">
</form>
<p> </p></td>
</tr>
</table>
<p> </p>
</body>
</html>