INSERT a recordset in a Table

prettem

Member
Hello Eugenio,
please support me with this Button Function:

I have a filtered view, I use the where_clause, and the following error occurs, and it randomly inserts the records in the tabel Versand

Thank you very much
Manuel

1656610749849.png
1656610907690.png


function dadabik_Versand_change_status()
{
global $conn, $dadabik_main_file, $quote, $where_clause, $table_name, $current_user;

$timestamp = time();
$datum = date("Y.m.d H:i:s", $timestamp);

$sql = "SELECT RechnungsID FROM Rechnung_Versand where $where_clause";.
$res_prepare = prepare_db($conn, $sql);
// $res_bind = bind_param_db($res_prepare, ':table_name', $table_name);
$res = execute_prepared_db($res_prepare,0);
//$row = fetch_row_db($res_prepare);

while ($row = fetch_row_db($res_prepare))
{
$re_id = $row['RechnungsID'];
//$sql = "INSERT INTO `Versand` (`status`, `rechnung_id`,`Type`, `versendet_am`,`ds_angelegt`,`ds_veraenderung`,`user`, `info`) VALUES ('
$sql = "INSERT INTO `Versand` (`status`, `rechnung_id`,`Type`) VALUES ('Ja', $re_id, 'Versand Rechnung')";
$res_prepare = prepare_db($conn, $sql);
$res = execute_prepared_db($res_prepare,0);
}

header('Location:'.$dadabik_main_file.'?tablename='.urlencode($table_name).'&function=search');
exit;
}

About/upgrade​

DaDaBIK™ is a product conceived and developed by Eugenio Tacchini
Copyright © 2001-2022 Eugenio Tacchini
Proudly ❤️ made in Emilia
dadabik.com

Your current DaDaBIK version​

You are using DaDaBIK version 11.6-Elba enterprise, installed on 16.06.2022 (installation code: 1780462288396de6b1), the latest version of DaDaBIK is 11.6-Elba released on 14.06.2022

You are running the latest release of DaDaBIK

In case you want to upgrade to a more powerful edition (from Pro to Enterprise/Platinum, from Enteprise to Platinum) please contact us.

System info​

PHP Version: 7.3.27

mysql version: 5.7.33-0ubuntu0.16.04.1

Web server: Apache

Client: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.67 Safari/537.36 OPR/87.0.4390.45
 

eugenio

Administrator
Staff member
Hello,
first of all I suggest you to use, for security reasons, prepared statements and placeholders, adding that $where_clause directly in your string is not safe. Also, I see a dot (.) after the semicolon.

Error during record fetching literally means there is an error when this line

$row = fetch_row_db($res_prepare

is executed. I haven't checked entirely your code and I don't know the context, but for sure one of the problems is that you are using again the same variable ($res_prepare) inside the loop, so after the first loop the variabile is not a recordset anymore.

Best,
 

prettem

Member
Hello,
thank you very much for the hint with variable ($res_prepare), I changed the name and everything works now :)

This Function is only for testing purposes, normally I am using prepared statements.

At this point I am happy to congratulate to your brilliant database solution, I am happy to use it.

best regards
Manuel
 
Top