Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: how to define variables as numeric  (Read 45067 times)

0 Members and 1 Guest are viewing this topic.

guitarzRus

    Topic Starter


    Rookie

    • Experience: Experienced
    • OS: Windows 7
    how to define variables as numeric
    « on: August 04, 2022, 05:21:33 PM »
    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".
    [/b]
    Code: [Select]
    <?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());
    ?>
    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

    BC_Programmer


      Mastermind
    • Typing is no substitute for thinking.
    • Thanked: 1140
      • Yes
      • Yes
      • BC-Programming.com
    • Certifications: List
    • Computer: Specs
    • Experience: Beginner
    • OS: Windows 11
    Re: how to define variables as numeric
    « Reply #1 on: August 04, 2022, 06:47:06 PM »
    Quote
    #1) how to define variables as numeric(I've tried several examples(forums and manuals)

    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: [Select]
    $prevbal="prevbal";

    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)

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

    $mysqli is undefined. You probably want the mysqli_query function.
    I was trying to dereference Null Pointers before it was cool.