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 11:19 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: error: function fetch_all()
PostPosted: Wed Aug 17, 2022 5:09 pm 
Offline

Joined: Tue Jun 16, 2015 1:03 am
Posts: 21
Quote:
Hi, once more trying to get a reasonable answer to this coding issue.
I'm a noobie with questions. I want to access a database table "payfile" and, based on the sum of
some of these fields, insert records into a database table "payhist". I realize now that I was in error
by trying to update and must insert records, with conditions, to a running history file. A lot of
research has gone into this and I thank so much for your patience and help. I'm lost from line 15-20.

[code]<?php
echo "<center>";echo date('m/d/y');echo "<br />";
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "prerentdb";
// Create connection
$mysqli = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: " . $mysqli->connect_error;
exit();
}

$amtpaid = filter_input(INPUT_GET, 'amtpaid'); // line 15
$sql = "SELECT * FROM payfile WHERE amtpaid=?"; // FROM payfile where amtpaid!=' '";

$stmt = $mysqli->prepare($sql);
// $stmt->bind_param($id);
$payfile = $stmt->get_result()->fetch_all(); // line 20
$due=0;
while($obj = fetch_object()){

$due = $obj->prevbal + $obj->latechg + $obj->secdep + $obj->damage + $obj->courtcost + $obj->NSF;
$amtdue = $obj->amtdue + due;
// if no payment or partial payment, add $10 to latechg field and amount not paid to prevbal field
$latechg = 0;
$prevbal = 0;
if ($obj->amtpaid < $obj->amtdue) {
$latechg += 10;
$prevbal = $obj->amtdue - $obj->amtpaid;
}
// if over-payment subtract over-payment
// from prevbal field
if ($amtpaid > $amtdue ) {
$amtdue = $amtpaid - $amtdue;
}
// $nsf doesn't get used or saved
$secdep = $damage = $courtcost = $nsf = 0;
// refresh every record - give every record the below values
$amtpaid = '0.00';
$hudpay = '0.00';
$datepaid = ' ';
$comment = ' ';
$paidsum = '0.00';

// prepare and bind
$stmt = $mysqli -> prepare("INSERT INTO payhist
(tenant, unit, amtpaid, amtdue, prevbal,latechg, secdep, damage, courtcost, nsf, paidsum, hudpay,
datepaid, comment, phone, cell)
VALUES
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$stmt -> bind_param("ssiiiiiiiiiissss",'$tenant','$unit','$amtpaid','$amtdue','$prevbal','$latechg',
'$secdep','$damage','$courtcost', '$nsf','$paidsum','$hudpay','$datepaid','$comment','$phone','$cell');

// set parameters and execute
$tenant='tenant';
$unit='unit';
$amtdue='amtdue'; // decimal field, not null
$amtpaid='amtpaid'; // decimal field, not null
$duedate='duedate';
$datepaid='datepaid';
$prevbal="prevbal"; // decimal field, not null
$latechg='latechg'; // decimal field, not null
$secdep='secdep'; // decimal field, not null
$damage='damage'; // decimal field, not null
$courtcost='courtcost'; // decimal field, not null
$nsf='nsf'; // decimal field, not null
$paidsum='paidsum'; // decimal field, not null
$hudpay='hudpay'; // decimal field, not null
$comment='comment';
$phone='phone';
$cell='cell';

$stmt -> execute();

echo "New records created successfully";
$stmt -> close();
}
?>[code]
Quote:
messages:
Fatal error: Uncaught Error: Call to a member function fetch_all() on bool on line 20


Top
 Profile  
 
 Post subject: Re: error: function fetch_all()
PostPosted: Wed Aug 24, 2022 6:50 am 
Offline
Site Admin

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

Code:
$amtpaid = filter_input(INPUT_GET, 'amtpaid'); // line 15


You should have this GET parameter here, e.g. http://localhost/index.php?amtpaid=5

Code:
$sql = "SELECT * FROM payfile WHERE amtpaid=?";
if ($stmt = $mysqli->prepare($sql)) {

    /* bind parameters for markers */
    $stmt->bind_param("s", $amtpaid);

    /* execute query */
    $stmt->execute();
    $result = $stmt->get_result();
}


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 42 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:  
Powered by phpBB © 2016 phpBB Group