note 26568 added to function.mysql-field-len
| From: | jowatkinsuk at yahoo dot co dot uk | Date: | Tue, 05 Nov 2002 12:49:32 +0000 |
| Subject: | note 26568 added to function.mysql-field-len | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-38990@lists.php.net to get a copy of this message | ||
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++;
}
}
--
http://www.php.net/manual/en/function.mysql-field-len.php
http://master.php.net/manage/user-notes.php?action=edit+26568
http://master.php.net/manage/user-notes.php?action=delete+26568
http://master.php.net/manage/user-notes.php?action=reject+26568