Jump to content

[SOLVED] Making a field display zero


kahodges

Recommended Posts

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

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">

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.