Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.