Jump to content

need codeing help


kirkwebsites

Recommended Posts

the amtdue doesn't print the 2 decimals, and the balance printed is wrong.  I've confirmed that all the amounts in the database are decimal(7,2) ??? This code worked when I was adding the paidamt to the balance.

 

<html><head>
<!--when the paidamt is keyed in, the current date, pd & balance are autoinserted-->
<script>
function $_(IDS) { return document.getElementById(IDS); }
function calculate_paid() {
   var pd = document.getElementById("pd");
   var datepaid = document.getElementById("datepaid");
   var amtdue = document.getElementById("amtdue");
   var paidamt = document.getElementById("paidamt");
   var balance = document.getElementById("balance");
// ********************set up date**********************
  var dateNow = new Date();
  var dayNow = dateNow.getDate();
  var datePaid = (dateNow.getMonth()+1)+"/"+dateNow.getDate()+"/"+dateNow.getFullYear();
datepaid.value = datePaid;
// ***************end date setup*************************
// ********calculate balance & set up pd*** 
amtdue.value = parseFloat(amtdue.value);
balance.value = parseFloat(balance.value) - parseFloat(paidamt.value);
pd.value = "P";
// ********************* end of calcs ******************
}
</script>
<script type="text/javascript">
window.google_analytics_uacct = "UA-256751-2";
</script>
<script type="text/javascript">
window.google_analytics_uacct = "UA-256751-2";
</script>
</head><body>
<?php
mysql_connect("localhost","root","");
mysql_select_db('oodb') or die( "Unable to select database");
if(!empty($_POST["submit"]))
{
$invnum = $_POST['invnum'];
$query="SELECT * FROM oocust Where invnum='$invnum'";
$result=mysql_query($query);
if(mysql_num_rows($result))
{
?>
<form action="#" method="post"><strong>Invoice Payment :</strong><br /><br /> 
<table cellspacing="0" cellpadding="0" border="1">  
   <tr>    
<th>Inv#</th>    
<th>check/ord#</th>    
<th>Name</th>    
<th>Description</th>    
<th>Paid Amt</th>    
<th>Amt Due</th>    
<th>Date Paid</th>    
<th>Code</th>    
<th>Balance</th>    
   </tr> 
<?php 
while($row = mysql_fetch_assoc($result))
   {
extract($row); 
?>  
<tr>   
<td><input type="text" size="5" name="invnum" value="<?php echo $invnum;?>" /></td>
<td><input type="text" size="5" name="ordernum" value="<?php echo $ordernum;?>" /></td>
<td><input type="text" size="25" name="bname" value="<?php echo $bname;?>" /></td>
<td><input type="text" size="25" name="descr" value="<?php echo $descr;?>" /></td>
<td><input type="text" size="7" id="paidamt" name="paidamt" value="<?php echo $paidamt;?>"
onBlur="calculate_paid(this);" /></td>   
<td><input type="text" size="7" id="amtdue" name="amtdue" value="<?php echo $amtdue;?>" /></td>
<td><input type="text" size="10" id="datepaid" name="datepaid" value="<?php echo $datepaid;?>"></td>   
<td><input type="text" size="1" id="pd" name="pd" value="<?php echo $pd;?>"></td>   
<td><input type="text" size="7" id="balance" name="balance" value="<?php echo $balance;?>"></td>     
</tr>  
<?php 
    } 
?> 
</table> 
<input type="submit" name="update" value="Make Payment" /> 
</form> 
<?php 
    }
else
    {  
echo "No listing for invoice no. $invnum.<br />Please select another.<br />"; 
    }
   }
if(isset($_POST["update"]))
  { 
$sql = "UPDATE oocust SET 
pd = '" . mysql_real_escape_string($_POST['pd']) . "',
datepaid = '" . mysql_real_escape_string($_POST['datepaid']) . "',
paidamt = '" . mysql_real_escape_string($_POST['paidamt']) . "',
amtdue = '" . mysql_real_escape_string($_POST['amtdue']) . "',
balance = '" . mysql_real_escape_string($_POST['balance']) . "'
WHERE invnum='".$_POST["invnum"]."'";
mysql_query($sql) or die("Update query failed: " . mysql_error());
echo "Record for invoice ".$_POST["invnum"]." has been updated";
}
?>
<form method="post" action="#">
<br />
<input type="text" name="invnum"/> <p>
<input type="submit" name="submit" value="select invoice no."/>
</form>
<script type="text/javascript"><!--
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
//-->
</script>
<script type="text/javascript"><!--
try {
var pageTracker = _gat._getTracker("UA-256751-2");
pageTracker._trackPageview();
} catch(err) {}
//-->
</script>
<script type="text/javascript"><!--
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
//-->
</script>
<script type="text/javascript"><!--
try {
var pageTracker = _gat._getTracker("UA-256751-2");
pageTracker._trackPageview();
} catch(err) {}
//-->
</script>
</body></html>

 

Link to comment
Share on other sites

I'm assuming this is javascript at the beginning?  You're missing the type="text/javascript" attribute inside that script tag.  Not sure this will make a difference, but it can't hurt to have the browser know how to interpret the code :)

 

Where exactly is the problem occurring?  Just on the echo at the end?  The problem doesn't seem to be on the PHP side but the javascript side since the amtdue and balance are calculated based on what is typed in for amount paid.  All that happens before PHP gets hold of anything. 

Link to comment
Share on other sites

I'm assuming this is javascript at the beginning?  You're missing the type="text/javascript" attribute inside that script tag.  Not sure this will make a difference, but it can't hurt to have the browser know how to interpret the code :)

 

That requirement has been dropped in HTML5. He's not using a doctype though.

Link to comment
Share on other sites

That's not what the HTML 4 spec says:

 

type = content-type [CI]

    This attribute specifies the scripting language of the element's contents and overrides the default scripting language. The scripting language is specified as a content type (e.g., "text/javascript"). Authors must supply a value for this attribute. There is no default value for this attribute.

http://www.w3.org/TR/html4/interact/scripts.html#h-18.2.1

Link to comment
Share on other sites

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.