earnest
earnest

Reputation: 261

mysqli insert keep giving error

I am trying to insert data into this table and I keep getting this error: Unknown column 'question2' in 'field list'

I have double checked and question2 column is part of the table. What in the code is wrong?

$q = mysqli_query ($dbc, 
    "INSERT INTO t_pornography (member_id, question1, question2, question3, question4, question5, question6, question7, question8, question9, question10, question11, question12, question13, question14, question15, question16, question17, question18, question19, question20) 
     VALUES ('$member_id', '$question1', '$question2', '$question3', '$question4', '$question5', '$question6', '$question7', '$question8',  '$question9',  '$question10',  '$question11',  '$question12',  '$question13',  '$question14',  '$question15', '$question16',  '$question17', '$question18', '$question19',  '$question20')"
);

Upvotes: 0

Views: 69

Answers (2)

earnest
earnest

Reputation: 261

Got it, column was not trimmed, had space that needed removal

Upvotes: 0

Berry Langerak
Berry Langerak

Reputation: 18859

I am trying to insert data into this table and I keep getting this error: Unknown column 'question2' in 'field list'

It's not, it's highly unlikely that the database is lying to you. My database never lies to me. The field 'question2' simply doesn't exist in the table 't_pornography'. You can check this by executing a simple select query:

$q = 'SELECT question2 FROM t_pornography';

That will surely give you the same error. Also, while you're at it, read up on normalisation. Having fields with the same name appended with a number generally is a sign that you're making a mistake.

Upvotes: 2

Related Questions