nicangeli Posted July 2, 2007 Share Posted July 2, 2007 Hello all, i am a complete n00b so take it easy. I am writign a script and have come to an issue. I am attempting to write data to a mysql database, but where i have the table name and field names etc i wish to use constants. I hope this makes sense. Below is code. $query = mysql_query("INSERT INTO TABLE_NAME (FIELD_NAME)"); where table_name and field_name are constants. Please help. If i have not explained this properly please just ask. Thanks again... Link to comment https://forums.phpfreaks.com/topic/58073-solved-mysql_query-with-php-constant/ Share on other sites More sharing options...
kael.shipman Posted July 2, 2007 Share Posted July 2, 2007 I think that PHP only interprets variables in double-quoted strings; not constants. Instead of defining TABLE_NAME and FIELD_NAME as constants, why not just define variables instead? It seems like that would be more standard procedure.... Even so, though, you could fix the problem by concatenating: <?php ... $query = mysql_query("INSERT INTO ".TABLE_NAME." (".FIELD_NAME.")"); ... ?> Link to comment https://forums.phpfreaks.com/topic/58073-solved-mysql_query-with-php-constant/#findComment-287952 Share on other sites More sharing options...
nicangeli Posted July 2, 2007 Author Share Posted July 2, 2007 thanks very much. That worked perfectly, (i knew i was overlookign something). The reason for me too use constants instead of variables is that i was not thinking at the time when i defined all the parts of my database in one file so that if i needed to rename parts of the database, then i would only have to had changed one line of code. Also i believed that a constant should be used as it cannot be changed by the script unlike a variable, however know i realise it make nout difference. Thanks again, Nick Link to comment https://forums.phpfreaks.com/topic/58073-solved-mysql_query-with-php-constant/#findComment-287969 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.