note 26568 deleted from function.mysql-field-len by didou
| From: | didou@php.net | Date: | Sat, 17 May 2003 20:48:45 +0000 |
| Subject: | note 26568 deleted from function.mysql-field-len by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-48241@lists.php.net to get a copy of this message | ||
Note Submitter: jowatkinsuk@yahoo.co.uk
A little function that uses mysql_field_len() to dynamically check that submitted forms do not
exceed allowed legth in the db.
function check_field_length($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;
static $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++;
}
}