d3chapma Posted November 24, 2006 Share Posted November 24, 2006 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 TRUEWhen 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 53Any ideas on why my statement is giving me this error? Quote Link to comment https://forums.phpfreaks.com/topic/28360-error-with-selectwhere-statement/ Share on other sites More sharing options...
printf Posted November 24, 2006 Share Posted November 24, 2006 [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 Quote Link to comment https://forums.phpfreaks.com/topic/28360-error-with-selectwhere-statement/#findComment-129799 Share on other sites More sharing options...
d3chapma Posted November 27, 2006 Author Share Posted November 27, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/28360-error-with-selectwhere-statement/#findComment-130909 Share on other sites More sharing options...
fenway Posted November 27, 2006 Share Posted November 27, 2006 Post the table structure for "form". Quote Link to comment https://forums.phpfreaks.com/topic/28360-error-with-selectwhere-statement/#findComment-131003 Share on other sites More sharing options...
d3chapma Posted November 27, 2006 Author Share Posted November 27, 2006 Well, I'm not sure how I should post the table structure. There are over 120 columns in that table. Is there an easy way for me to show you that? Quote Link to comment https://forums.phpfreaks.com/topic/28360-error-with-selectwhere-statement/#findComment-131032 Share on other sites More sharing options...
d3chapma Posted November 27, 2006 Author Share Posted November 27, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/28360-error-with-selectwhere-statement/#findComment-131045 Share on other sites More sharing options...
d3chapma Posted November 27, 2006 Author Share Posted November 27, 2006 Well, would you look at that defaultform has a space in front of it. That was my problem right there. Everything works now. Quote Link to comment https://forums.phpfreaks.com/topic/28360-error-with-selectwhere-statement/#findComment-131077 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.