Form field hitting a 255 character counter next to a database column definition being widened

You paste a store’s returns policy into an admin form, press Save and find that half the paragraph has disappeared. Raising the textarea limit won’t help if PHP trims the input or MySQL rejects it. A text field character limit is a contract between the form, application and database. The smallest effective limit wins.

couponPHP is a self-hosted PHP coupon and deal script with store descriptions, coupon text and user fields. Its recovered 2016 article widened many columns in version 2.1. That SQL remains below for reference, but a current repair should identify the affected field rather than alter almost every text column.

Find the text field character limit in each layer

An editor that stops accepting input suggests a browser text field character limit. Failure on Save suggests server validation or storage. Check maxlength, editor settings, the submitted request and saved value.

MDN’s HTML documentation (2026) defines maxlength in UTF-16 code units [1]. For example:

<label for="description">Store description</label>
<textarea id="description" name="description" maxlength="10000"></textarea>

A plain Latin letter counts as one code unit. A supplementary Unicode code point counts as two. A visible symbol can contain multiple code points, so a displayed “character” counter needs a documented definition. Browser restrictions also aren’t server-side protection: a custom request can bypass them.

Check your real schema with read-only queries before editing it:

SELECT VERSION(), @@sql_mode, @@character_set_connection;
SHOW CREATE TABLE stores;
SHOW FULL COLUMNS FROM stores;
SHOW INDEX FROM stores;

Allow for table prefixes. Check the platform requirements and version history before changing the schema.

MySQL VARCHAR and TEXT use different limits

VARCHAR(255) declares 255 characters, subject to table limits. With utf8mb4, they can require 255 × 4 = 1,020 payload bytes. VARCHAR adds a one- or two-byte length prefix; this example can require two.

Modern MySQL permits a VARCHAR declaration up to 65,535, constrained by the shared 65,535-byte row limit. Ignoring other columns and overhead, the utf8mb4 ceiling is floor((65,535 − 2) ÷ 4) = 16,383 characters. Your table’s limit can be lower.

TEXT has a different payload limit: 65,535 bytes. Carnegie Mellon’s university-hosted historical MySQL manual documents the TEXT storage formula as L + 2 bytes with L < 2^16 [2]. Its old VARCHAR rules should not be used for a modern server.

The IETF’s UTF-8 specification (2003) defines one to four bytes per Unicode code point. These exact limits follow from that byte budget:

MySQL typeMaximum payload bytesMaximum all-four-byte code points
TINYTEXT25563
TEXT65,53516,383
MEDIUMTEXT16,777,2154,194,303
LONGTEXT4,294,967,2951,073,741,823

For TEXT, 16,383 × 4 = 65,532 leaves three payload bytes; the two-byte length prefix is separate. ASCII-only TEXT can reach 65,535 characters. Mixed content permits fewer characters. Packet and memory limits can reduce practical capacity.

Match PHP validation to the form

PHP and JavaScript can disagree about length. Publish your text field character limit and validate it server-side. This example matches HTML’s 10,000-code-unit rule and protects TEXT storage:

<?php
$text = $_POST['description'] ?? '';
if (!is_string($text) || !mb_check_encoding($text, 'UTF-8')) {
    http_response_code(422);
    exit('Provide valid UTF-8 text.');
}
$units = intdiv(strlen(mb_convert_encoding($text, 'UTF-16LE', 'UTF-8')), 2);
if ($units > 10000 || strlen($text) > 65535) {
    http_response_code(422);
    exit('Description exceeds the permitted length.');
}
// Save using a parameterized query and an utf8mb4 connection.

This needs mbstring. strlen() counts bytes; UTF-16LE conversion matches HTML’s units. Preserve rejected drafts instead of silently cutting them. Length validation doesn’t replace HTML sanitization or safe output escaping.

Widen descriptions without weakening identifiers

A description may merit TEXT or MEDIUMTEXT. Permalinks usually need bounded VARCHAR values and suitable uniqueness constraints. Don’t widen both because one description failed.

The patch recreates ordinary prefix indexes, potentially losing earlier uniqueness. A 200-character utf8mb4 prefix can require 200 × 4 = 800 bytes; check engine limits. Preserve nullability, collation, defaults and constraints.

University of Maryland guidance (2026) recommends utf8mb4, strict SQL mode and inspected migrations [4]. Strict mode helps reject overlength nonspace data. Migrations may lock or rebuild tables; MySQL DDL isn’t a multi-statement rollback plan. Test backup restoration first. Plugins may add tables; support can help identify your schema.

The original 2016 database patch

Archive notice: Published on 2 September 2016. The “65,535 characters” statement below applies only to single-byte content; TEXT’s general limit is 65,535 bytes. Do not run this broad, index-changing patch on an unexamined production database. The original SQL statements are retained, with code fencing repaired.

By default 2.1 version of the CouponPHP script has some too small limits to some text fields like for example Store description field preventing you from saving large text there. Here we share a part of 2.2 version that lifts up limits of almost all the text fields in the script to 65,535 characters. Just execute this SQL code in your PhpMyAdmin

alter table categories drop index perma;
alter table categories modify perma text;
create index perma on categories(perma(200));
alter table categories modify title text;
alter table categories modify thumbnail text;
alter table categories modify icon text;
alter table category_keywords modify keyword text;
alter table clicks modify user_ip text;
alter table clicks modify user_agent text;
alter table clicks modify url text;
alter table clicks modify referrer text;
alter table collections modify title text;
alter table collections modify icon text;
alter table collections drop index perma;
alter table collections modify perma text;
create index perma on collections(perma(200));
alter table collections modify thumbnail text;
alter table coupons modify thumbnail text;
alter table coupons drop index coupon_code;
alter table coupons modify code text;
create index coupon_code on coupons(code(200));
alter table coupons modify title text;
alter table coupons modify description text;
alter table coupons modify url text;
alter table email_queue modify email text;
alter table email_queue modify subject text;
alter table pages drop index permalink;
alter table pages modify permalink text;
create index permalink on pages(permalink(200));
alter table pending_coupons modify thumbnail text;
alter table pending_coupons drop index coupon_code;
alter table pending_coupons modify code text;
create index coupon_code on pending_coupons(code(200));
alter table pending_coupons modify url text;
alter table pending_coupons modify title text;
alter table pending_coupons modify description text;
alter table settings drop index title;
alter table settings modify title text;
create index title on settings(title(200));
alter table stores modify title text;
alter table stores drop index perma;
alter table stores modify perma text;
create index perma on stores(perma(200));
alter table stores drop index domain;
alter table stores modify domain text;
create index domain on stores(domain(200));
alter table stores modify affiliate_url text;
alter table subscriptions modify email text;
alter table users drop index username;
alter table users modify username text;
create index username on users(username(200));
alter table users modify password text;
alter table users drop index email;
alter table users modify email text;
create index email on users(email(200));
alter table users modify about_me text;
alter table users modify website text;
alter table users modify avatar text;
alter table users drop index fb_id;
alter table users modify facebook_id text;
create index fb_id on users(facebook_id(200));
alter table users modify facebook_session text;
alter table users modify twitter_id text;
alter table users modify twitter_token text;
alter table users modify twitter_secret text;
alter table admin drop index username;
alter table admin modify username text;
create index username on admin(username(200));
alter table admin drop index password;
alter table admin modify password text;
create index password on admin(password(200));

In case you have the Blog Plugin installed execute also this code:

alter table blog_categories modify title text;
alter table blog_categories modify perma text;
alter table blog_posts modify title text;
alter table blog_posts modify excerpt text;
alter table blog_posts modify perma text;
alter table blog_posts modify featured_image text;
alter table blog_tags modify tag text;
alter table blog_tags modify perma text;

Frequently asked questions

Does HTML maxlength count characters or bytes?

HTML maxlength counts UTF-16 code units, not storage bytes or necessarily visible characters. A basic Latin letter uses one code unit; a supplementary Unicode character uses two. MySQL utf8mb4 stores each Unicode code point in one to four bytes. Your browser counter and PHP validation must therefore use a deliberately chosen counting rule.

Can a MySQL TEXT field hold 65,535 emoji?

No. TEXT permits 65,535 bytes of payload, not 65,535 arbitrary Unicode characters. If each code point uses four UTF-8 bytes, the field holds at most 16,383 of them, with three bytes left over. An emoji sequence may contain several code points, so the number of visible emoji can be lower still.

Should I convert every VARCHAR column to TEXT?

No. Long descriptions may suit TEXT, but usernames, email identifiers and permalinks need deliberate length and index choices. A broad conversion can remove useful constraints, alter column attributes or change index behavior. Back up first, inspect the actual schema and test a migration that changes only the fields your application needs.

References

  1. MDN, HTML maxlength attribute, 2026
  2. Carnegie Mellon-hosted historical MySQL manual, storage requirements, accessed 2026
  3. IETF, UTF-8 specification RFC 3629, 2003
  4. University of Maryland, Relational Database Design and MySQL, 2026