i am trying to submit a form to the mysql database using php the following error is resulting.


Error: Unknown column 'unit1_code' in 'field list'


what could be the problem

Dani AI

Generated

asked for the table definition and the full query — that is the quickest way to diagnose this. Common causes when MySQL says a column is "unknown" even though it appears in phpMyAdmin are usually one of these:

  • The query is treating a string literal or PHP variable as a column (missing quotes or wrong interpolation).
  • Backticks were used around a value instead of around an identifier (backticks make MySQL look for a column).
  • The code is running against a different database/table than expected (check the connection and database name).
  • A simple spelling/case mismatch or accidental hidden character in the column name.

Quick checks to run on the server (replace names as needed):

DESCRIBE your_table;
SHOW CREATE TABLE your_table;
SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS
  WHERE TABLE_SCHEMA='your_db' AND TABLE_NAME='your_table';

A typical mistake and fix (conceptual):

-- problematic: value treated as identifier
INSERT INTO subjects (unit1_code) VALUES (unit1_code);

-- correct for literal or variable
INSERT INTO subjects (unit1_code) VALUES ('unit1_code');

Better: use prepared statements so PHP does the quoting/binding for you:

$stmt = $mysqli->prepare("INSERT INTO subjects (unit1_code, other) VALUES (?, ?)");
$stmt->bind_param("ss", $unit1_code, $other);
$stmt->execute();

Extra tips: echo the exact SQL string your PHP sends and check mysqli_error()/PDOException for the full message; avoid using backticks around VALUES; verify the connection selects the expected database; and confirm column spelling by copy/pasting from DESCRIBE to eliminate hidden characters. As suggested, include the CREATE TABLE output and the exact SQL/PHP that builds the query for precise diagnosis.

Recommended Answers

All 3 Replies

There is no column with that name (unit1_code) in your table.

the column is there it is the third column

Show your table definition, the entire query and the complete error message.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.