physaux Posted November 4, 2009 Share Posted November 4, 2009 Here is my try at it: <?php $tableFields = mysql_list_fields("DB_NAME", "TABLE_NAME"); $columns = mysql_num_fields($tableFields); //LINE 21 for ($i = 0; $i < $columns; $i++) { $field_array[] = mysql_field_name($tableFields, $i); } if (!in_array(NEW_COLUMN; $field_array)) { $result = mysql_query("ALTER TABLE `".TABLE_NAME."` ADD `".NEW_COLUMN."` INT(11) NOT NULL DEFAULT ‘1′;"); echo "ADDED TABLE<br>"; }else{ echo "ALREADY EXISTS<br>"; } ?> I just get a blank screen, no output. Idk anyone got any ideas? EDIT: I now get this error: mysql_num_fields() expects parameter 1 to be resource, boolean given in Line 21 Link to comment https://forums.phpfreaks.com/topic/180329-solved-how-to-check-if-a-column-exists-if-not-then-make-it-not-working-help-please/ Share on other sites More sharing options...
mrMarcus Posted November 4, 2009 Share Posted November 4, 2009 check this line: if (!in_array(NEW_COLUMN; $field_array)) change out that ; for a , you have error_reporting on? you should've received a parse error. EDIT: what is ‘1′; at the end of the query? Link to comment https://forums.phpfreaks.com/topic/180329-solved-how-to-check-if-a-column-exists-if-not-then-make-it-not-working-help-please/#findComment-951264 Share on other sites More sharing options...
physaux Posted November 4, 2009 Author Share Posted November 4, 2009 I have no clue why that semicolon got there, it is just a comma in my code. I even copy- pasted it. It was changing my apostraphes to encoded crazy values so I removed them and put " in preview before post. check this line: if (!in_array(NEW_COLUMN; $field_array)) change out that ; for a , you have error_reporting on? you should've received a parse error. EDIT: what is ‘1′; at the end of the query? Link to comment https://forums.phpfreaks.com/topic/180329-solved-how-to-check-if-a-column-exists-if-not-then-make-it-not-working-help-please/#findComment-951268 Share on other sites More sharing options...
physaux Posted November 4, 2009 Author Share Posted November 4, 2009 I added the following under the first line: if($tableFields===true or $tableFields===false) echo "WAS BOOLEAN"; my page says "WAS BOOLEAN" why am I getting a boolean? EDIT: aaaaaahhhh I see what i did, I had my "CONSTANT" in quotes... Link to comment https://forums.phpfreaks.com/topic/180329-solved-how-to-check-if-a-column-exists-if-not-then-make-it-not-working-help-please/#findComment-951270 Share on other sites More sharing options...
simshaun Posted November 4, 2009 Share Posted November 4, 2009 Do a var_dump on it instead. It returns a result resource. Since mysql_list_fields is deprecated, did you try the alternate method shown in the docs? Link to comment https://forums.phpfreaks.com/topic/180329-solved-how-to-check-if-a-column-exists-if-not-then-make-it-not-working-help-please/#findComment-951273 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.