How to restrict PHP mail from sending email to spam folder

`I tried the code below but it is still sending to SPAM folder. Kindly help me to figure this out such that emails goes to INBOX only.

function sendEmail($content,$email,$phone){
  $headers = "Reply-To: Danuel <".$email.">rn";
  $headers .= "Return-Path:Danuel <".$email.">rn";
  $headers .= "From:Danuel <".$email.">rn"; 
  $headers .= "Organization:Danuel internationalrn";
  $headers .= "MIME-Version: 1.0rn";
  $headers .= "Content-type: text/plain; charset=iso-8859-1rn";
  $headers .= "X-Priority: 3rn";
  $headers .= "X-Mailer: PHP". phpversion() ."rn";
  $to ="[email protected]";
  $subject ="Number ".$phone." Banned";
  return mail($to, $subject, $content, $headers);
}

if(isset($_POST['send'])){
    $content='Hey';
    
    if(sendEmail($content,$_POST['email'],$_POST['phone'])==1){
       echo"<small><font color=green>Sent</font></small>";
    }else{
       echo"<small><font color=red>Failed</font></small>";
    }
}

PHP Modify Variable

There is a PHP file called test2.php,the code is in follow:

<?php
$data=array(
    'name' => 'jack',
    'age' => 8,
);
?>

I want to modify the $data in anoher php file called test1.php,
but i find that if only use:

require_once "./test2.php";
$data['age']=10;
echo $data['age'];

Although the output is 10,but $data in test2.php dosen’t change.

I want to know how to edit a PHP file in anoher PHP file.

The pages options.php in wordpress gives 403 error

The options.php file inside wp-admin which was working fine few days ago is now giving me 403 error suddenly. There was no change made and it gives me this error out of nowhere.
I tried doing few workarounds suggested online which included checking file permissions, deactivating and activating plugins and checking .htaccess file but none of these worked out.
It would be of great help if something can be suggested on solving this issue, thanks

install ionCube loader for PHP 8.1.2 and Ubuntu 22.04

I have a Ubuntu server 22.04 and I have installed PHP 8.1.2, MySQL 8, and Apache2 then I installed WordPress’s latest version. I did this introduction (Link)
After I installed and enabled the new theme (Harika) I got the “ionCube PHP loader needs to be installed”

Then I did Everything that is on this (Link) page to fix the error, but when I browse the WordPress home page I get HTTP ERROR 500 (This page isn’t working).

Please help me.
Thanks.

The best way to insert bulk data to database in Laravel 9 that has multiple table to insert or relations

I want to create bulk insert data in my project, I’m using MariaDB / MySQL and laravel as a PHP framework. Actually, I can do something like this in my case

$data = [
    ['name' => 'Joh Doe', 'code' => '1234'],
    ['name' => 'Mr Lorem', 'code' => '5678'],
    ['name' => 'Mr Ipsum', 'code' => '9012'],
    //...
];

MyTable::insert($data);

But, the problem is, I don’t just insert the data into 1 table, there are 5 tables that I have to enter data from and all of these tables are related to 1 main table. Here’s the single insert code that I made.

$myPost = MyTable::create(['name' => 'Joh Doe', 'code' => '1234']);

$myPost->ownedCar()->create([
    'merk' => 'defaultMerk',
    'qty' => 1,
    'fuel' => 'gasoline'
]);

$myPost->ownedBike()->create([
    'merk' => 'defaultMerk',
    'qty' => 1,
]);

$myPost->ownedBicycle()->create([
    'merk' => 'defaultMerk',
    'wheel' => 2
    'qty' => 1,
]);

$myPost->moneyOwned()->create([
    'currency' => 'USD',
    'value' => '696969',
]);

Okay, that is the single insert that I made. And here’s the bulk version that I made using a loop (LOL hahaha)

// let says $datas is form request

foreach($datas as $data) {
    $myPost = MyTable::create(['name' => $data['name'], 'code' => $data['code']]);

    $myPost->ownedCar()->create([
        'merk' => 'defaultMerk',
        'qty' => 1,
        'fuel' => 'gasoline'
    ]);

    //....
}

Okay, maybe there is no something wrong with my loop (I guess haha), but, what if the data that I insert to the form is more than 10k? or maybe 1k, it will take so long. So, there is the best way to solve this kind of issue? thanks

Laravel 9 Validator Make Method Not Seems To Be Working

I have written this code in the Controller as the Action of a form:

public function submitAsk(Request $request)
    {
        $rules = [
            'title' => 'required|max:255',
            'description' => 'required|max:1000',
            'category' => 'required',
            'tags' => 'required',
        ];

        $messages = [
            'required' => ':attribute can not be empty'
        ];

        $validator = Validator::make($request, $rules, $messages);

        if ($validator->fails()) {
            return redirect('questions/ask')
                ->withErrors($validator)
                ->withInput();
        }

        ...
    }

But I get this error:

IlluminateValidationFactory::make(): Argument #1 ($data) must be of type array, IlluminateHttpRequest given, called in C:projectnamevendorlaravelframeworksrcIlluminateSupportFacadesFacade.php on line 338

So what’s going wrong here?

How can I solve this issue?

Why Session variable is always empty on a forwarded domain [closed]

I have a hosting account that can host only one domain. However, I created a sub folder and forwarded another domain to that folder which contains an index.php file.
This worked fine until I decided to add a login mechanism. I executed login script and forwarded the user to another sub folder.

This is my login code

$userPwd = $_POST['pwd'];
$userName = $_POST['un'];
$dbPwd;

    $dbPwd=$dbCls->db->query("SELECT Password FROM users WHERE TRIM(UserName)='" .$userName ."';")->fetch_assoc()['Password'];
        
    if(strcmp(hash("sha256",$userPwd .salt()),$dbPwd)==0){
        //Hash match
        $_SESSION['UserId']=$dbCls->db->query("SELECT UserID FROM malinduusers WHERE TRIM(UserName)='" .$userName ."';")->fetch_assoc()['UserID'];
        $_SESSION['UserName']=$userName;
        header("Location:../Dashboard/");
    }

But the problem is, when I forward to the subfolder, the $_SESSION variable is always empty, through I started the session with session_start();.

array(0){}

This is not a problem for the main hosted domain. For that, the $_SESSION is not reset and working fine.

PHP – Notice: Undefined index [duplicate]

I am doing a hospital management project I got an error while doing it can anyone solve it

<?php 
include("include/connection.php");
if (isset($_POST['apply'])) {
    $firstname=$_POST['fname'];
    $surname = $_POST['sname'];
    $username = $_POST['uname'];
    $email = $_POST['email'];
    $gender = $_POST['gender'];
    $phone = $_POST['phone'];
    $country = $_POST['country'];
    $password = $_POST['pass'];
    $confirm_password = $_POST['con_pass'];


    $error=array();



    if (empty($firstname)) { 
        $error[ 'apply'] = "Enter Firstname";
    }else if(empty($surname)){
        $error['apply'] = "Enter Surname";
    }else if (empty($username)){
        $error['apply'] = "Enter Username";
    }else if(empty($email)){
        $error['apply'] = "Enter Email Address";
    }else if($gender == ""){
        $error[ 'apply']="Select Your Gender";
    }else if(empty($phone)){
        $error['apply'] = "Enter Phone Number";
    }else if($country == ""){
        $error['apply'] = "Select Country";
    }else if (empty($password)){
        $error['apply'] = "Enter Password";
    }else if($confirm_password != $password){
        $error[ 'apply'] = "Both Password do not match";
    }

}

I am getting the following errors
this is showing while running it
it is very help full if anyone answer it

Why construct method gives errors inside class file – PHP

I just opened new project and this is class file example:

<?php

namespace AppTest;

class Sky
{
    public function __construct(private readonly string $registration, private readonly Airline $airline)
    {
    }

    public function getRegistration(): string
    {
        return $this->registration;
    }

    public function getAirline(): Airline
    {
        return $this->airline;
    }
}

And i have errors like:

Method should either have body or be abstract
Using '$this' when not in object context

But when i change constructor to this:

    public function __construct(string $registration,Airline $airline)
    {
    }

then i don’t have errors, does someone knows to explain why? because i think there is some problem that im not aware of

PHP able to receive post request with a raw text but its giving error when post same data raw json

I’m posting data to my API endpoint. it’s simple JSON data. But I’m getting error 404 when posting data as raw JSON but if I post the same data at the same endpoint as raw text its works.

working as raw text

getting error 404 as raw JSON

<?php
    var_dump(http_response_code());
    var_dump($_POST);
    echo file_get_contents("php://input");
        
  ?>

I have removed all code from the API end point and just trying to print post data.

Sample JSON :

{
    "object": "whatsapp_business_account",
    "entry": [
        {
            "id": "456",
            "changes": [
                {
                    "value": {
                        "messaging_product": "whatsapp",
                        "metadata": {
                            "display_phone_number": "123456789",
                            "phone_number_id": 123456789
                        },
                        "contacts": [
                            {
                                "profile": {
                                    "name": "NAME"
                                },
                                "wa_id": 123456789
                            }
                        ],
                        "messages": [
                            {
                                "from": 123456789,
                                "id": "wamid.ID",
                                "timestamp": 123456789,
                                "text": {
                                    "body": "MESSAGE_BODY"
                                },
                                "type": "text"
                            }
                        ]
                    },
                    "field": "messages"
                }
            ]
        }
    ]
}
 

I have checked JSON and it’s a valid JSON. no special character but still unable to solve this issue.

One more thing its working on my local machine under XAMPP but not on Linux shared server.

How to take info from a SQL Database to populate a json obj & encode object in base64 and send via post to an api using laravel

So our platform operates on Laravel/PHP/SQL/JS/Dart/Flutter/SQL/Firebase and our payment processor has an rest api in which we need to work with to send a digital invoice out for payment. Now the processor requires information (Basics Name, Email, Amount, Phone, Ipaddress, Order Number, etc.) to be included in the api call some of which won’t be available or known until after the order is placed on our system. Necessitating a spinner widget to place the order in a pending payment status to then fire the api call to collect payment after. Additionally all requests made to the api need to be converted to base64 encoding prior to being sent over the api.

According to the api documentation It says that i need to create a json object containing all the required information and encode that data using Base64 Encoding which is then sent via a put request to the api to obtain a response alongside a Payment token which will then need to be stored to be called upon later using a callback api get request. I am trying to figure out the best way to accomplish this so that our payment flow becomes:

Customer Shops Via Web / App adding items to cart
Clicks or Taps on the Confirm Order Button

Our App/Platform creates a “draft order” with a order status of pending payment & sends the necessary information to our processor to generate a digital invoice & payment token where the token is stored in our database with the rest of the order data & processor then send a text message to the customer with a link to complete DIV (Digital Identity Verification) & collect payment for the order.

Customer then follows the link & completes payment where processor indicates if the given orders payment was successful or unsuccessful in it’s system while our platform sends an additional api request using the payment tokens to get the current payment status for orders sitting in the “pending payment status” so our platform can mark the order as paid and update it’s status to processing.

I know i will invariably receive a response of why does your payment methodology need to be so complex just get processing and go and as much as we would love for that to be the case, it simply is just not possible at the moment in our industry and current political climate. Forcing us to use this type of payment methodology to be able to operate or be restricted to simply being cash only.

To be honest I have not yet attempted, as i am still trying to map out what this needs in order to work and am seeking advice on the best practical way to accomplish this using the frameworks/stack that we operate on. Admittedly i am feeling slightly intimidated by this project since management just kind of threw this in my lap after losing our backend server side developer. I am not super familiar with Laravel and am somewhat familiar with PHP however most of my background is in Flutter, Dart, Kotlin, Swift, Html, CSS, JS, React & management does not seem to know the difference and somehow expect me to make this work.

This is the stack we are currently using

  • PHP/Laravel for our Administrative Control Panel. This is where this functionality needs to be added.
  • SQL for database.
  • Flutter/Dart for Mobile app / Front End.
  • Firebase for OTP/Push Notifications etc.

Query needs to be made to database after order placement grabbing order info and placing it into a json object

Expected result should look like:


{

'ipAddress':'123.456.789.012',

'merchantId': '1234567890',

'invoicenumber': '1234',

'firstName':'Mary',

'lastName':'Jane',

'email':'[email protected]',

'currency':'USD',

'amount' : '1000',

'redirectURL':'example.com',

'apiKey': 'Rw309njyNnklbkf9Pn6YNx68494292EV'

}

Where the json object data needs to be encoded using Base64 Encoding

Where the output of that encoding should look like this:

ew0KDQonaXBBZGRyZXNzJzonMTIzLjQ1Ni43ODkuMDEyJywNCg0KJ21lcmNoYW50SWQnOiAnWENwUjQyOTInLA0KDQonZmlyc3ROYW1lJzoncmFqZXNoJywNCg0KJ2xhc3ROYW1lJzonZ29uZGFsaXlhJywNCg0KJ2VtYWlsJzonZW1haWxAZW1haWwuY29tJywNCg0KJ2N1cnJlbmN5JzonVVNEJywNCg0KJ2Ftb3VudCcgOiAnMTAwMCcsDQoNCidyZWRpcmVjdFVSTCc6J2V4YW1wbGUuY29tJywNCg0KJ2FwaUtleSc6ICdSdzMwOW5qeU5ua2xia2Y5UG42WU54Njg0OTQyOTJFVicNCg0KfQ==

Which will also then need to be stored temporarily as a string with the field name of RTPRequest

Where the encrypted string is then passed via a post request to the api endpoint

Where the response from the api endpoint will include a payment token in the body which will be needed to be added to the database table row for the order that was just sent to the api

API get callback request is then sent requesting an updated payment status and if successful updates the payment status to paid and the orders status from pending payment to processing taking the user to from the order processing spinner to their orders page.

Thoughts, suggestions, advice etc…

PHP vers. 5.6 or 5.5 on Windows 11 – Error “No input file specified.”

I’m having trouble installing PHP with the old version 5.6 or below (5.2 is running well) on my Windows 11 machine. I know it is not recommended to run this old version, but in fact, I need to do so at the moment.
I don’t know if the best place for asking this question is stackoverflow or serverfault. Please let me know, if stackoverflow is not the right place.
I know that this question is already asked several times, but all solutions did not help in my case. I already googled a lot this error message, but all hints did not work for me. Here are some links I had a look at:

PHP error: “No input file specified.” in IIS 10.0, PHP 5.6 on local development server

“No input file specified” for some versions of PHP

and many more.

The error is, that I’m getting always the message

No input file specified.

when trying to open a PHP page.
I already tried IIS as webserver as well as Apache, but the error is the same. So I assume it is not an issue of the webserver, but PHP.
In Apache I’m getting more information in the error.log file.

I already tried to set the document_root in PHP and Apache to the exact same location. I already tried to comment out the document_root and open_basedir as described in other posts. The PHP version is a fresh download from https://windows.php.net/downloads/releases/archives/. I used the file php.ini-production template as php.ini. I just changed display_errors to On. The rest of the php.ini has not been changed (except doc_root trying to outcomment).

The configuration of PHP in the Apache webserver looks like this:

<IfModule fcgid_module>
FcgidInitialEnv PHPRC "D:/PHP/v5.5.38-nts-Win32-VC11-x86"
<FilesMatch .(php|html)$>
    SetHandler fcgid-script
</FilesMatch>
FcgidWrapper "D:/PHP/v5.5.38-nts-Win32-VC11-x86/php-cgi.exe" .php
FcgidWrapper "D:/PHP/v5.5.38-nts-Win32-VC11-x86/php-cgi.exe" .html
</IfModule>

I’ve set the Apaches’ webserver LogLevel to trace8 to get more information.
This is being written in the error log file of Apache, when I’m trying to access i.e. the phpinfo.php file.

[Sat Dec 31 11:23:18.338359 2022] [core:trace5] [pid 16684:tid 1184]
protocol.c(711): [client ::1:50400] Request received from client: GET
/phpinfo.php HTTP/1.1

[Sat Dec 31 11:23:18.339347 2022] [http:trace4]
[pid 16684:tid 1184] http_request.c(435): [client ::1:50400] Headers
received from client:

[Sat Dec 31 11:23:18.339347 2022] [http:trace4]
[pid 16684:tid 1184] http_request.c(438): [client ::1:50400] Host:
localhost

[Sat Dec 31 11:23:18.339347 2022] [http:trace4] [pid
16684:tid 1184] http_request.c(438): [client ::1:50400] Connection:
keep-alive

[Sat Dec 31 11:23:18.339347 2022] [http:trace4] [pid
16684:tid 1184] http_request.c(438): [client ::1:50400]
Cache-Control: max-age=0

[Sat Dec 31 11:23:18.339347 2022]
[http:trace4] [pid 16684:tid 1184] http_request.c(438): [client
::1:50400] sec-ch-ua: “Not?A_Brand”;v=”8″,
“Chromium”;v=”108″, “Google Chrome”;v=”108″

[Sat Dec
31 11:23:18.339347 2022] [http:trace4] [pid 16684:tid 1184]
http_request.c(438): [client ::1:50400] sec-ch-ua-mobile: ?0 [Sat
Dec 31 11:23:18.339347 2022] [http:trace4] [pid 16684:tid 1184]
http_request.c(438): [client ::1:50400] sec-ch-ua-platform:
“Windows”

[Sat Dec 31 11:23:18.339347 2022] [http:trace4] [pid
16684:tid 1184] http_request.c(438): [client ::1:50400]
Upgrade-Insecure-Requests: 1

[Sat Dec 31 11:23:18.339347 2022]
[http:trace4] [pid 16684:tid 1184] http_request.c(438): [client
::1:50400] User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36

[Sat Dec 31 11:23:18.339347 2022] [http:trace4] [pid 16684:tid 1184]
http_request.c(438): [client ::1:50400] Accept:
text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9

[Sat Dec 31 11:23:18.339347 2022] [http:trace4] [pid 16684:tid 1184]
http_request.c(438): [client ::1:50400] Sec-Fetch-Site: none [Sat
Dec 31 11:23:18.339347 2022] [http:trace4] [pid 16684:tid 1184]
http_request.c(438): [client ::1:50400] Sec-Fetch-Mode: navigate

[Sat Dec 31 11:23:18.339347 2022] [http:trace4] [pid 16684:tid 1184]
http_request.c(438): [client ::1:50400] Sec-Fetch-User: ?1

[Sat Dec
31 11:23:18.339347 2022] [http:trace4] [pid 16684:tid 1184]
http_request.c(438): [client ::1:50400] Sec-Fetch-Dest: document

[Sat Dec 31 11:23:18.339347 2022] [http:trace4] [pid 16684:tid 1184]
http_request.c(438): [client ::1:50400] Accept-Encoding: gzip,
deflate, br

[Sat Dec 31 11:23:18.339347 2022] [http:trace4] [pid
16684:tid 1184] http_request.c(438): [client ::1:50400]
Accept-Language: de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7

[Sat Dec 31 11:23:18.339347 2022] [http:trace4] [pid 16684:tid 1184]
http_request.c(438): [client ::1:50400] Cookie:
remember_web_59ba36addc2b2f9401580f014c7f58ea4e30989d=eyJpdiI6ImpTL0F1Sk1RSmErdTdzQTlRME53bmc9PSIsInZhbHVlIjoidll4SFZ6SHA3WmFZRnVMZ3ZqS0I0cnpURlFKckJJdWExNTFHNmtlUWd2bFA2WFd0YlM4bG9QUWoyb2Q1NkpMU2pvcW9NZGY5M3dVTUUxdUYxbHc3RTBUa2lTZGhkT05takNTRnhNRkRPMzU5NDRCdklJcERidFdreHFMQm1KRnJsQ2twLzhPZEVSa2lZS2hGUTRNUDQwSnY3QUlHcGkvRWx5QU1naUF1UGFTWVRmbGJDU2dOTlp3MVp6aTV2ZDZmTjJpSjJFamJwNG9sak5SR2UxR3BnRDM1aUNnbTVZL2RKblN1YzBsL2l0VT0iLCJtYWMiOiI1MGU3MzMyZmFlZDgxNjQ1NjI3MjNmZWFmYTU4YzhlMWJlZjQzN2RiZTZjMjM5MjQ4NjRiMTliZjY5OTYyM2E0IiwidGFnIjoiIn0%3D;
HttpOnly; __utmc=111872281;
__utmz=111872281.1671477985.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utma=111872281.881906265.1671477985.1671477985.1671559722.2; PHPSESSID=k77fg6s7n5fnf42aq3851bbn04

[Sat Dec 31 11:23:18.339347 2022]
[authz_core:debug] [pid 16684:tid 1184] mod_authz_core.c(815): [client
::1:50400] AH01626: authorization result of Require all granted:
granted

[Sat Dec 31 11:23:18.339347 2022] [authz_core:debug] [pid
16684:tid 1184] mod_authz_core.c(815): [client ::1:50400] AH01626:
authorization result of : granted

[Sat Dec 31 11:23:18.339347 2022] [core:trace3] [pid 16684:tid 1184]
request.c(360): [client ::1:50400] request authorized without
authentication by access_checker_ex hook: /phpinfo.php

[Sat Dec 31 11:23:18.340339 2022] [core:trace4] [pid 16684:tid 1184]
util_script.c(568): [client ::1:50400] Headers from script
‘phpinfo.php’:

[Sat Dec 31 11:23:18.340339 2022] [core:trace4] [pid
16684:tid 1184] util_script.c(571): [client ::1:50400] Status: 404
Not Found

[Sat Dec 31 11:23:18.340339 2022] [core:trace1] [pid
16684:tid 1184] util_script.c(650): [client ::1:50400] Status line
from script ‘phpinfo.php’: 404 Not Found

[Sat Dec 31 11:23:18.340339
2022] [core:trace4] [pid 16684:tid 1184] util_script.c(571): [client
::1:50400] X-Powered-By: PHP/5.5.38

[Sat Dec 31 11:23:18.340339
2022] [core:trace4] [pid 16684:tid 1184] util_script.c(571): [client
::1:50400] Content-type: text/html

[Sat Dec 31 11:23:18.340339 2022]
[http:trace3] [pid 16684:tid 1184] http_filters.c(1129): [client
::1:50400] Response sent with status 404, headers:

[Sat Dec 31 11:23:18.340339 2022] [http:trace5] [pid 16684:tid 1184]
http_filters.c(1138): [client ::1:50400] Date: Sat, 31 Dec 2022
10:23:18 GMT

[Sat Dec 31 11:23:18.340339 2022] [http:trace5] [pid
16684:tid 1184] http_filters.c(1141): [client ::1:50400] Server:
Apache/2.4.54 (Win64) mod_fcgid/2.3.10-dev

[Sat Dec 31 11:23:18.340339
2022] [http:trace4] [pid 16684:tid 1184] http_filters.c(959): [client
::1:50400] X-Powered-By: PHP/5.5.38

[Sat Dec 31 11:23:18.340339
2022] [http:trace4] [pid 16684:tid 1184] http_filters.c(959): [client
::1:50400] Keep-Alive: timeout=5, max=100

[Sat Dec 31 11:23:18.340339 2022] [http:trace4] [pid 16684:tid 1184]
http_filters.c(959): [client ::1:50400] Connection: Keep-Alive

[Sat Dec 31 11:23:18.340339 2022] [http:trace4] [pid 16684:tid 1184]
http_filters.c(959): [client ::1:50400] Transfer-Encoding: chunked

[Sat Dec 31 11:23:18.340339 2022] [http:trace4] [pid 16684:tid 1184]
http_filters.c(959): [client ::1:50400] Content-Type: text/html [Sat
Dec 31 11:23:18.340339 2022] [core:trace6] [pid 16684:tid 1184]
core_filters.c(828): [client ::1:50400] writev_nonblocking: 286/286

Does anyone have a hint / link / tip for solving this issue? Many thanks in advance.
If any information is missing in this thread, please let me know. I will provide the information as soon as possible.

How do I dynamically add Laravel HTML content to a dynamically embedded Laravel blade using jQuery?

I am developing a web application using Laravel and jQuery.

There is a parent Laravel blade that contains a form.
The form contains checkboxes to chose combinations of two object types A and B.
The change of checkboxes trigger an AJAX request which replaces the content of a div container inside the form with another embedded Laravel blade.
The contents of the embedded Laravel blade are dependent on the combinations of chosen objects of type A and B.
An object of type B has parameters whose values should be set via radio buttons in the embedded Laravel blade.
The combination of one object of A, one object of B and a combination of parameter values for parameters of object B are contained in one div in the embedded blade.

How do I add an ‘add’ button in the embedded blade per combination of object A and object B to enable configuration for more than one combination of parameter values for object A and object B?

See code snippets below. I tried to boil it down to the essential.

I came up with dynamic individual HTML IDs for div container and ‘add’ button for a combination of object A and object B in embedded.blade.php.
Then I wanted to reference these dynamic IDs with jQuery to register an event per ‘add’-Button that adds HTML containing PHP variables in the right div container.
When I run the whole thing it throws no errors but when I click on any of the ‘add’ buttons the new HTML is not appended to the corresponding div but to only one of the divs in the embedded blade.
That might be due to the fact that the referencing of the dynamic IDs does not work as I expect it to.
It seems to me that only the last element of each of the two arrays respectively the values of the last iteration of the loops in the tag of embedded.blade.php are used for my prefix variable.

Is it even good practice to use dynamically generated HTML IDs? Or is it bad practice, should I avoid it?
Especially in the context of referencing them by jQuery?

Do I miss something here in the whole run process or order of how PHP/Laravel and JavaSCript/jQuery are executed in combination especially regarding variable substitution?

parent.blade.php

<form id="formAjax">
    <div>
        @foreach($objectsOfTypeA as $objectOfTypeA)
            <label>
                <input 
                    type='checkbox'
                    id="{{$objectOfTypeA->id}}" 
                    name="objectOfTypeA[]" 
                    value="{{$objectOfTypeA->id}}">
            </label>
        @endforeach
    </div>
    <div>
        @foreach($objectsOfTypeB as $objectOfTypeB)
            <label>
                <input 
                    type='checkbox'
                    id="{{$objectOfTypeB->id}}" 
                    name="objectOfTypeB[]" 
                    value="{{$objectOfTypeB->id}}">
            </label>
        @endforeach
    </div>    
    <div>
        <div id="radioButtonDiv"></div> <!-- This is the div container whose content shall be replaced by the embedded.blade.php with AJAX. -->
    </div>
</form>

ajax-file.js

const formdata = $("#formAjax").serialize();
$.ajax({
    type: "POST",
    url: "/ajax/radioButtonDiv",
    data: { formData: formdata },
    success: function (data) {
      $("#radioButtonDiv").html(data.htmlSrc);
    },
});

web.php

Route::group([
    'prefix' => 'ajax'
], function () {
    Route::post('/radioButtonDiv', [AjaxController::class, 'getRadioButtonDiv']);
});

AjaxController.php

class AjaxController extends Controller {

    public function getRadioButtonDiv(Request $request) {
        
        // Get data for object types A and B from database
        
        return response()->json(['htmlSrc' => view('somefolder/embedded')
                    ->with('arrayOfObjectsTypeA', $arrayOfObjectsTypeA)
                    ->with('arrayOfObjectsTypeB', $arrayOfObjectsTypeB)
                    ->render()]);
    }

}

embedded.blade.php

@if(isset($arrayOfObjectsTypeA))
    @foreach($arrayOfObjectsTypeA as $objectOfTypeA)
        <h3>{{$objectOfTypeA->name}}</h3>
        @if(isset($arrayOfObjectsTypeB))
            @foreach($arrayOfObjectsTypeB as $objectOfTypeB)
                <h4>{{$objectOfTypeB->name}}:</h4>
                <div id="{{$objectOfTypeA->name}}-{{$objectOfTypeB->name}}-parent-div">
                    <div> <!-- This div container is to be copied on add-button click within the parent div to select other variations of parameter values for the same combination of $objectOfTypeA and $objectOfTypeB and $objectOfTypeB->parameters -->
                        @foreach($objectOfTypeB->parameters as $parameter)
                            <div>    
                                <h5 class="title">{{$parameter->name}}</h5>
                                @foreach($parameter->parameterOptions as $option)
                                    <input type="radio"
                                            id="{{$option->name.$option->id}}"
                                            name="parameterOptions[{{"$objectOfTypeA->id"}}-{{$objectOfTypeB->id}}][{{"$parameter->id"}}]"
                                            value="{{$option->id}}"
                                    <label for="{{$option->name}}">{{$option->name}}</label><br>
                                @endforeach
                            </div>
                        @endforeach
                    </div>
                </div>
                <button 
                    type='button' 
                    id="{{$objectOfTypeA->name}}-{{$objectOfTypeB->name}}-add-button"
                    >
                    Add <!-- Add another div container with radio buttons for the same combination of $objectOfTypeA and $objectOfTypeB and $objectOfTypeB->parameters to chose another variation of parameter values -->
                </button>
            @endforeach
        @endif
    @endforeach
@endif

<script>
    $("#radioButtonDiv").ready(function() {
        var arrayOfObjectsTypeA = @json($arrayOfObjectsTypeA);
        var arrayOfObjectsTypeB = @json($arrayOfObjectsTypeB);
        for (const objectOfTypeA of arrayOfObjectsTypeA) {
            for (const objectOfTypeB of arrayOfObjectsTypeB) {
                var prefix = (objectOfTypeA.name + "-" + objectOfTypeB.name).toLowerCase();
                $("#" + prefix + "-add-button").on("click", function () {
                    $(
                        `<div>
                            @foreach($objectOfTypeB->parameters as $parameter)
                                <div>
                                    <h5 class="title">{{$parameter->name}}</h5>
                                    @foreach($parameter->parameterOptions as $option)
                                        <input type="radio"
                                                id="{{$option->name.$option->id}}"
                                                name="parameterOptions[{{"$objectOfTypeA->id"}}-{{$objectOfTypeB->id}}][{{"$parameter->id"}}]"
                                                value="{{$option->id}}"
                                        <label for="{{$option->name}}">{{$option->name}}</label><br>
                                    @endforeach
                                </div>
                            @endforeach
                        </div>`
                    ).appendTo("#" + prefix + "-parent-div");
                }); 
            }
        }
    }
</script>

why i cannot mix prepared statements and PDO query()? [duplicate]

Why the following code prints nothing?:

<?php
error_reporting(E_ALL);
$db = new PDO("sqlite::memory:");
$db -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->exec("CREATE TABLE IF NOT EXISTS book (
  id INTEGER PRIMARY KEY,
  name text,
  amount integer,
  day text
);
");

$stmt = $db->prepare('insert into book(name,amount,day) 
        values(:name,:amount,:day)');
        $stmt->bindValue(':name', 'foo', SQLITE3_TEXT);
        $stmt->bindValue(':amount', 102, SQLITE3_INTEGER);
        $stmt->bindValue(':day', '2022-12-28', SQLITE3_TEXT);
        $stmt->execute();

$result = $db->query("select * from book where `name`='foo'");
foreach($result as $r){
                        print $r['name']."n";
}

When i insert the row with PDO query(), then it would work, why?

How to pass variables to PHP script & return values from PHP script using Python?

I have a Python script called “cal.py” & PHP script called DBfun.php which contains DB calls.

In my DBfun.php script,I have function called
function get_sby_name($f_haddress,$f_sdesc)
and I need to pass below #1 & #2 variables to this PHP script and take DB results to Python script and print.

I tried below #3 code part,but cannot pass variables to PHP function from python script.
If there is any way to do this ?

Python Script: cal.py

f_haddress=10.228.86.74 #1
f_sdesc='GR1-SW' #2
f_notify_type=''

#I tried this code part in Pyton file  #3
#import subprocess #3
#proc = subprocess.Popen("php /path/to/src/DBfun.php", shell=True, stdout=subprocess.PIPE) #3
#script_response = proc.stdout.read() #3


if(f_notify_type=="PROBLEM"):
  f_color="#FF0000"
  f_adesc="Status:OK"

else:
  f_color="#AEB6BF"
  f_adesc="Status:Warning"

print(f_color+''+f_adesc)