I have created a field in MySQL named “pid”, which I use in PHP coding at the end of other variable names to indicate which of 7 template designs a user has created. The limit is 7, at which point they are given a message that they have reached their limit.
I have the code working EXCEPT when the field is blank (before user creates the first template). When I hard-code a “0” it works. But, obviously, I need to use the “{pid}” variable to pick up the template sequence in the database.
Here is the PHP:
<?PHP
$pid = {pid};
$total_templates = 7;
if ($total_templates > $pid) {
echo "<a href='create.template.php'><img src='create_template.png'></a>";
} else {
echo "<b style='color: #CC0000'>Your limit of $pid Templates has been reached";
}
?>
How do I get the code to convert a blank field in MySQL to “0” in conjunction with the above code?
If I understand your question, could you not set it to
0if it isempty()?You can also set the default value for that field in mysql. If you are using phpAdmin, go to the table and click the “Change” action and set the default value there. If you need sql command to do this, I can get that for you too.