CodeLobster IDE

Free cross-platform PHP IDE (HTML, PHP, CSS, JavaScript, Python code editor) with support Drupal, Joomla, Twig, JQuery, BackboneJS, LaravelJS, Node.js, CodeIgniter, CakePHP, Laravel, Magento, MeteorJS, Phalcon, Symfony, VueJS, WordPress, Yii
It is currently Thu Mar 28, 2024 2:37 pm

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: how to define variables as numeric
PostPosted: Thu Aug 04, 2022 11:12 pm 
Offline

Joined: Tue Jun 16, 2015 1:03 am
Posts: 21
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".

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

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

=  +  +  +  +  + ; // Warning: A non-numeric value encountered x 5 line 21
=  + ;  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 ( < )  // Notice: Undefined variable: amtpaid
   {  =  + 10;  =  - ;  }
// if payment = amtdue clear due
if ( == ) // Notice: Undefined variable: amtpaid
   {  = 0;  = 0; }
// if over-payment subtract over-payment
// from prevbal field
if ( >  )  // Notice: Undefined variable: amtpaid
{  =   - ;   = 0;  = 0;  }
= 0;  = 0;  = 0;  = 0;

// refresh every record - give every record the below values
= '0.00';
= '0.00';
= ' ';
= '0.00';
= ' ';

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

Quote:
these are error messages:

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

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

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

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

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

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

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

Notice: Undefined variable: ampaid in C:
mpp\htdocs\property
efreshpayments.php on line 32

Notice: Undefined variable: mysqli in C:
mpp\htdocs\property
efreshpayments.php on line 44

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


Top
 Profile  
 
 Post subject: Re: how to define variables as numeric
PostPosted: Fri Aug 05, 2022 7:38 am 
Offline
Site Admin

Joined: Wed Sep 12, 2007 2:18 pm
Posts: 3931
Hi.

1)
$x = 24535;
var_dump(is_numeric($x));

2) If You want to get a sum then

$num1 = "12.5";
$num2 = "15.5";
$result = floatval($num1) + floatval($num2);

If You want to store 2 values then You should create an array

$array = array();
$array[] = $num1;
$array[] = $num2;

3) There is some truncated code here.
Here is the sample of correct code:


$con = mysqli_connect("localhost","root","","prerentdb");

// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
}

$con->query("select * FROM payfile");

Regards,
Codelobster Team.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 41 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2016 phpBB Group