Thank you, Thank you, Thank you, you've stopped me from going mad.
This function might be of use to someone else, so here's the final version. It'll go through each form posted and dynamically check that no inputs are greater than the field length allowed in the db.
function check_field_length($table)
{
$field_result = mysql_query ("SELECT * FROM $table");
$fields = mysql_list_fields("PDS", $table);
//count how many fields in form posted and delete 2 for buttons
$numposts = count($_POST);
$actualposts = $numposts-2;
$i=1;
foreach ($_POST as $key => $value)
{
if ($i <= $actualposts)
{
$type = mysql_field_type($fields, $i);
if ($type == "string")
{
$max = mysql_field_len($fields, $i);
$length = strlen($value);
//echo "$key, max = $max, length=$length<br/>";
if ($length > $max)
{
echo "<p><font color=\"#ff0000\">PROBLEM</font> $key must be no greater than $max characters.";
echo "<br/>Please go back and correct.</p>";
exit;
}
}
}
$i++;
}
}