Jump to content

Error with SELECT.....WHERE... Statement


d3chapma

Recommended Posts

I'm trying to select a field in a row of a table where a boolean field is set to True. The field name is 'title', the table name is 'form' and the boolean field is 'default' and in the same table. The statement I am using is as follows:

SELECT title FROM form WHERE default IS TRUE

When I try to use this statement in a query it I get the following error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\form\includes\DbConnector.php on line 53

Any ideas on why my statement is giving me this error?
Link to comment
https://forums.phpfreaks.com/topic/28360-error-with-selectwhere-statement/
Share on other sites

[b]DEFAULT[/b] is a MySQL reserved word, so you should change that column/field name to some other name. You can still use it but it's not recommend. It you still insist on using it, then just enclose it with backticks [b]`[/b]column[b]`[/b]...

[code]$sql = "SELECT title FROM form WHERE `default` IS TRUE";[/code]


printf
Ok, so I changed my column name to defaultform so now the code now reads:

[code] SELECT * FROM form WHERE defaultform IS TRUE [/code]


and the error that I am getting from mysql_error() is:

[code] Unknown column 'defaultform' in 'where clause' [/code]


I have checked and double checked to make sure that there were not any typos in my code or the table. I am 100% certain that there is a column named defaultform.

Any ideas?
The results of "SHOW CREATE TABLE form" is as follows:

CREATE TABLE `form` (\n  `id` int(11) NOT NULL auto_increment,\n  ` defaultform` tinyint(1) NOT NULL,\n  `frequency` tinyint(4) NOT NULL,\n  `title` text NOT NULL,\n  `question1` text NOT NULL,\n  `q1type` tinyint(4) NOT NULL,\n  `q1ans1` text NOT NULL,\n  `q1ans2` text NOT NULL,\n  `q1ans3` text NOT NULL,\n  `q1ans4` text NOT NULL,\n  `q1ans5` text NOT NULL,\n  `q1ans6` text NOT NULL,\n  `q1ans7` text NOT NULL,\n  `q1ans8` text NOT NULL,\n  `question2` text NOT NULL,\n  `q2type` tinyint(4) NOT NULL,\n  `q2ans1` text NOT NULL,\n  `q2ans2` text NOT NULL,\n  `q2ans3` text NOT NULL,\n  `q2ans4` text NOT NULL,\n  `q2ans5` text NOT NULL,\n  `q2ans6` text NOT NULL,\n  `q2ans7` text NOT NULL,\n  `q2ans8` text NOT NULL,\n  `question3` text NOT NULL,\n  `q3type` tinyint(4) NOT NULL,\n  `q3ans1` text NOT NULL,\n  `q3ans2` text NOT NULL,\n  `q3ans3` text NOT NULL,\n  `q3ans4` text NOT NULL,\n  `q3ans5` text NOT NULL,\n  `q3ans6` text NOT NULL,\n  `q3ans7` text NOT NULL,\n  `q3ans8` text NOT NULL,\n  `question4` text NOT NULL,\n  `q4type` tinyint(4) NOT NULL,\n  `q4ans1` text NOT NULL,\n  `q4ans2` text NOT NULL,\n  `q4ans3` text NOT NULL,\n  `q4ans4` text NOT NULL,\n  `q4ans5` text NOT NULL,\n  `q4ans6` text NOT NULL,\n  `q4ans7` text NOT NULL,\n  `q4ans8` text NOT NULL,\n  `question5` text NOT NULL,\n  `q5type` tinyint(4) NOT NULL,\n  `q5ans1` text NOT NULL,\n  `q5ans2` text NOT NULL,\n  `q5ans3` text NOT NULL,\n  `q5ans4` text NOT NULL,\n  `q5ans5` text NOT NULL,\n  `q5ans6` text NOT NULL,\n  `q5ans7` text NOT NULL,\n  `q5ans8` text NOT NULL,\n  `question6` text NOT NULL,\n  `q6type` tinyint(4) NOT NULL,\n  `q6ans1` text NOT NULL,\n  `q6ans2` text NOT NULL,\n  `q6ans3` text NOT NULL,\n  `q6ans4` text NOT NULL,\n  `q6ans5` text NOT NULL,\n  `q6ans6` text NOT NULL,\n  `q6ans7` text NOT NULL,\n  `q6ans8` text NOT NULL,\n  `question7` text NOT NULL,\n  `q7type` tinyint(4) NOT NULL,\n  `q7ans1` text NOT NULL,\n  `q7ans2` text NOT NULL,\n  `q7ans3` text NOT NULL,\n  `q7ans4` text NOT NULL,\n  `q7ans5` text NOT NULL,\n  `q7ans6` text NOT NULL,\n  `q7ans7` text NOT NULL,\n  `q7ans8` text NOT NULL,\n  `question8` text NOT NULL,\n  `q8type` tinyint(4) NOT NULL,\n  `q8ans1` text NOT NULL,\n  `q8ans2` text NOT NULL,\n  `q8ans3` text NOT NULL,\n  `q8ans4` text NOT NULL,\n  `q8ans5` text NOT NULL,\n  `q8ans6` text NOT NULL,\n  `q8ans7` text NOT NULL,\n  `q8ans8` text NOT NULL,\n  `question9` text NOT NULL,\n  `q9type` tinyint(4) NOT NULL,\n  `q9ans1` text NOT NULL,\n  `q9ans2` text NOT NULL,\n  `q9ans3` text NOT NULL,\n  `q9ans4` text NOT NULL,\n  `q9ans5` text NOT NULL,\n  `q9ans6` text NOT NULL,\n  `q9ans7` text NOT NULL,\n  `q9ans8` text NOT NULL,\n  `question10` text NOT NULL,\n  `q10type` tinyint(4) NOT NULL,\n  `q10ans1` text NOT NULL,\n  `q10ans2` text NOT NULL,\n  `q10ans3` text NOT NULL,\n  `q10ans4` text NOT NULL,\n  `q10ans5` text NOT NULL,\n  `q10ans6` text NOT NULL,\n  `q10ans7` text NOT NULL,\n  `q10ans8` text NOT NULL,\n  `question11` text NOT NULL,\n  `q11type` tinyint(4) NOT NULL,\n  `q11ans1` text NOT NULL,\n  `q11ans2` text NOT NULL,\n  `q11ans3` text NOT NULL,\n  `q11ans4` text NOT NULL,\n  `q11ans5` text NOT NULL,\n  `q11ans6` text NOT NULL,\n  `q11ans7` text NOT NULL,\n  `q11ans8` text NOT NULL,\n  `question12` text NOT NULL,\n  `q12type` tinyint(4) NOT NULL,\n  `q12ans1` text NOT NULL,\n  `q12ans2` text NOT NULL,\n  `q12ans3` text NOT NULL,\n  `q12ans4` text NOT NULL,\n  `q12ans5` text NOT NULL,\n  `q12ans6` text NOT NULL,\n  `q12ans7` text NOT NULL,\n  `q12ans8` text NOT NULL,\n  PRIMARY KEY  (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=latin1

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.