kahodges Posted March 11, 2009 Share Posted March 11, 2009 I have a field used to display numerical data. I'm using it to display the amount of deductions used for payroll purposes. The field would require the numbers between 0 and 10. The problem I am running into is the field retaining and displaying zero once it's submitted through the form. All other numbers retain and display as they are supposed to. Example: In the field, I type in number 1 and submit. I go back to the same form, the field displays 1. If I go to the same form, and type in number 0 (zero), hit submit, the form comes back blank. I need the form to retain and display 0 (zero) if that's the number entered. Here is the code I am using: <td colspan="2"><input name="deduction" type="text" id="deduction" <?php if (!empty($deduction)) echo "value=\"$deduction\""; ?>><div class="highlight" id="inf_deduction"> The database field is set up as MySQL 5.0 - field, varchar 12, latin1_swedish_ci, no attributes, null, default null, no extras. Thanks in advance for your help. Link to comment https://forums.phpfreaks.com/topic/148961-solved-making-a-field-display-zero/ Share on other sites More sharing options...
MadTechie Posted March 11, 2009 Share Posted March 11, 2009 OKay first the reason for the problem 0 = empty the fix <td colspan="2"><input name="deduction" type="text" id="deduction" <?php if (!empty($deduction) && !is_numeric($deduction)) echo "value=\"$deduction\""; ?> ><div class="highlight" id="inf_deduction"> Link to comment https://forums.phpfreaks.com/topic/148961-solved-making-a-field-display-zero/#findComment-782160 Share on other sites More sharing options...
sasa Posted March 11, 2009 Share Posted March 11, 2009 try <td colspan="2"><input name="deduction" type="text" id="deduction" <?php if ($deduction !='') echo "value=\"$deduction\""; ?>><div class="highlight" id="inf_deduction"> look http://hr.php.net/empty Link to comment https://forums.phpfreaks.com/topic/148961-solved-making-a-field-display-zero/#findComment-782166 Share on other sites More sharing options...
kahodges Posted March 11, 2009 Author Share Posted March 11, 2009 Thank you both very much for the quick replies. I tried yours MAdTechie, but still ended up with the same results. However, using Sasa's solution did the trick. Again, Thanks. Link to comment https://forums.phpfreaks.com/topic/148961-solved-making-a-field-display-zero/#findComment-782182 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.