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
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:
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.
Jump to Post— pritaeas 2,276There is no column with that name (unit1_code) in your table.
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.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.