How do I store a simple code like this : if ($variable) echo "variable set"; else echo "variable not set"; in a database and then have it executed in a php file..
You can store it as a string. However, I do warn against such use of eval() as it could lead to malicious code being executed.
I know I have to use eval(), but i receive a lot of string errors and also a very ambigous one : unexpected T_IF although the syntax is correct.
.
If you are mixing it with HTML code, then you would need to use the PHP start/end tags to differentiate it from the non-PHP code.
If you were using the above format for your If Statmement, that syntax is wrong, because your leaving out the brackets: { } .
That is fine. Leaving out braces where the statement that follows is the entire block is perfectly valid syntax. I do not recommend it as it can be more error prone, but this depends on the situation (and personal taste and carelessness).