Software > Computer programming

how to define variables as numeric

(1/1)

guitarzRus:

--- Quote ---Hi, I have some issues with my code. It's to refresh account payfile at end of month. Comments are noted
in code (//).
#1) how to define variables as numeric(I've tried several examples(forums and manuals)
#2) how to add several variables together so they are known as numeric(they are all decimal 8,2 in the database)
#3) Please, someone explain the "Undefined variable: mysql".

--- End quote ---
[/b]

--- Code: ---<?php
//Open a new connection to the MySQL server
$link = mysqli_connect("localhost", "root", "", "prerentdb"); 

// Check connection
if($link === false){ die("ERROR: Could not connect. " . mysqli_connect_error()); }
//MySqli Select Query
$sql = "select * FROM payfile";
echo "<center>";echo date('m/d/y');echo "<br />";
$due=0;
  $prevbal="prevbal";
  $latechg="latechg";
   $secdep="secdep";
   $damage="damage";
$courtcost="courtcost";
      $nsf="nsf";
   $amtdue="amtdue";
   $amtpaid="amtpaid";
  $paidsum="paidsum";

$due = $prevbal + $latechg + $secdep + $damage + $courtcost + $nsf; // Warning: A non-numeric value encountered x 5 line 21
$amtdue = $amtdue + $due;  Warning: // A non-numeric value encountered x 1 line 22

// if no payment or partial payment, add $10 to latechg field and amount not paid to prevbal field
if ($amtpaid < $amtdue)  // Notice: Undefined variable: amtpaid
{ $latechg = $latechg + 10; $prevbal = $amtdue - $amtpaid;  }
// if payment = amtdue clear due
if ($amtpaid == $amtdue) // Notice: Undefined variable: amtpaid
{ $prevbal = 0; $latechg = 0; }
// if over-payment subtract over-payment
// from prevbal field
if ($ampaid > $amtdue )  // Notice: Undefined variable: amtpaid
{ $amtdue = $amtpaid  - $amtdue;  $prevbal = 0; $latechg = 0;  }
$secdep = 0; $damage = 0; $courtcost = 0; $nsf = 0;

// refresh every record - give every record the below values
$amtpaid = '0.00';
$hudpay = '0.00';
$datepaid = ' ';
$paidsum = '0.00';
$comments = ' ';

// Perform a query, check for error
if (!$mysqli -> query("UPDATE payfile SET // Undefined variable: mysqli 
Fatal error: Uncaught Error: Call to a member function query() on null 
 prevbal='$prevbal',latechg='$latechg', hudpay='$hudpay', amtpaid='$amtpaid', 
datepaid='$datepaid', comment='$comment', paidsum='$paidsum' 
where unit = $unit"));
mysqli_query($sql) or die(mysql_error());
?>
--- End code ---

--- Quote ---these are error messages:

Warning: A non-numeric value encountered in C:\xampp\htdocs\property\refreshpayments.php on line 21

Warning: A non-numeric value encountered in C:\xampp\htdocs\property\refreshpayments.php on line 21

Warning: A non-numeric value encountered in C:\xampp\htdocs\property\refreshpayments.php on line 21

Warning: A non-numeric value encountered in C:\xampp\htdocs\property\refreshpayments.php on line 21

Warning: A non-numeric value encountered in C:\xampp\htdocs\property\refreshpayments.php on line 21

Warning: A non-numeric value encountered in C:\xampp\htdocs\property\refreshpayments.php on line 21

Warning: A non-numeric value encountered in C:\xampp\htdocs\property\refreshpayments.php on line 22

Notice: Undefined variable: ampaid in C:\xampp\htdocs\property\refreshpayments.php on line 32

Notice: Undefined variable: mysqli in C:\xampp\htdocs\property\refreshpayments.php on line 44

Fatal error: Uncaught Error: Call to a member function query() on null  on line 44
--- End quote ---

BC_Programmer:

--- Quote ---#1) how to define variables as numeric(I've tried several examples(forums and manuals)

--- End quote ---

You assign them numeric values. You are assigning strings to variables, and then trying to add those strings together.
I'll answer your question with another question:


--- Code: ---$prevbal="prevbal";

--- End code ---

This assigns the string value "prevbal" to the $prevbal variable.


--- Quote ---#2) how to add several variables together so they are known as numeric(they are all decimal 8,2 in the database)
--- End quote ---

So I take it you think your assignments are somehow pulling from the database? I do not know why you would have that impression. You need to perform a query, read the first row, and then assign the fields from that row to those variables.



--- Quote ---#3) Please, someone explain the "Undefined variable: mysql".

--- End quote ---

$mysqli is undefined. You probably want the mysqli_query function.

Navigation

[0] Message Index

Go to full version