How can I secure MySQL query to prevent SQL injections? [duplicate]

In my PHP project I use the code below:

$all_text_filter = '';
if(isset($_REQUEST['q'])) {
if($_REQUEST['q'] != '') {
$all_text_filter = $_REQUEST['q'];
$all_text_filter = ' AND (r.recipe_name LIKE "%'.$all_text_filter.'%")';
}
}

$all_text_filter = '';

if (isset($_REQUEST['q']) && $_REQUEST['q'] != '') {
$search_terms = explode(' ', $_REQUEST['q']);

$text_conditions = [];

foreach ($search_terms as $term) {
$term = trim($term);

if (!empty($term)) {
$text_conditions[] = '(r.recipe_name LIKE "%' . $term . '%" OR ri.ingredient_name IS NOT NULL AND ri.ingredient_name LIKE "%' . $term . '%")';
}
}

if (!empty($text_conditions)) {
$all_text_filter = ' AND (' . implode(' OR ', $text_conditions) . ')';
}
}

How can I secure the code for MySQL injections and prevent the users from entering malicious code in the input field?

Possibility of Flutter with PHP for Google Places API

For almost all of my flutter app’s API calls, I send them through PHP hosted on my server and return the data to flutter, and this has always worked well.

The reasons for this are:

  1. I don’t have to expose my API keys.
  2. Flexibility to make changes in my server and php, without always having to release a new app.
  3. Saving on data (single call to my server, which then collates the data from various API sources)

However with Google Places Autocomplete API, I’m unsure if this method is still a good way. It would mean repeated calls to my server, to fetch the API response (predictions) from Google, then return it Flutter to be displayed. This could cause it to be slow responding?

The only option I’ve come up with, is adding a delay to when textediting controller is updated, to when the data is fetched, which could reduce the total number of requests being made.

I’m really hoping someone has other suggestions I could try, to make the user experience not feel laggy.

NOTE: I use session tokens with my API requests.

How to log 404 errors in Laravel 10?

Laravel doesn’t log 404 errors by default. I want to change this behavior.

Most guides say to log it manually in the following block :

public function register(): void
{
    $this->reportable(function (Throwable $e) {
        // Handle 404 here
    });
}

but it seems like 404 exceptions don’t even trigger this method for some reason.

Doing the following technically works but it’s tedious to put everywhere I need it :

try {
     $model = User::findOrFail(99999);
} catch (ModelNotFoundException $e) {
     Log::error($e);
     throw $e;
}

I’m using Laravel 10.

What am I doing wrong ?

Uncaught exception from mysqli_sql_exception catch block

I have this code where I absorb mysqli_sql_exception, log it and throw a new exception with a more generic error message that can be displayed to the user. However the new exception is not being caught by the second catch.

try {
    $query = "Use any invalid query here";
    mysqli_query($connect, $query);

} catch (mysqli_sql_exception $e){
    writeToLog("Failed to update in Line 301. Error: ".$e->getMessage()."nQuery: $query");
    throw new Exception("Failed to cancel booking. Please try again or contact support."); // <-- error source

} catch (Exception $e) {
    $_SESSION['msg'] = ['type' => 'warning', 'content' => $e->getMessage()];
} 

I get this error

Fatal error: Uncaught Exception: Failed to cancel booking. Please try again or contact support. 

There are no namespaces being used in this file and I’ve tried all combinations of backslashes. What am I doing wrong?

Return with multi Values

I have a mysql database, dtb drive

f_id data target
1 2024-03-05 Berlin
2 2024-05-06 Berlin
3 2024-04-01 Hanover
4 2024-03-15 Hamburg
5 2024-06-03 Hanover
6 2024-06-01 Hamburg
7 2024-05-16 Duisburg
8 2024-05-02 Frankfurt

I now want to output a list on my HTML page. The list should be sorted by date and only contain Berlin, Duisburg and Hamburg.

I’m failing with PHP and return array because of the two different values.
If someone could help me with this I would be very grateful.

php composer dependency internal server error

I installed a dependency (Minishlink Web-Push) via composer2 on my server. The installation returned a success and in my homepages file manager I find the files composer.json and composer.lock now.

The files show the dependency I want to use.

However, sending an Ajax POST request to my php file returns an internal server error as soon as I enter a piece of code that is trying to access the dependency. I tried several ways to access the dependency, but it does not work.

Internal server Error:

POST <MY_URL> 500 (Internal Server Error)

My php file, accessed with an Ajax POST request:


if ($_SERVER["REQUEST_METHOD"] == "POST") {


    // probably needed to initialize an instance of my dependency
    $auth = [
        'VAPID' => [
            'subject' => 'https://<MY_DOMAIN>',
            'publicKey' => '<SERVER_PUBLIC_KEY>',
            'privateKey' => '<SERVER_PRIVATE_KEY>'
        ]
    ];



    // I tried all eight options below:

    $webPush = new MinishlinkWebPushWebPush($auth);
    //ERROR: PHP Fatal error:  Uncaught Error: Class "MinishlinkWebPushWebPush" not found in /home/<USER>/domains/<MY_DOMAIN>/public_html/push/subscription.php

    $webPush = new MinishlinkWebPushWebPush($auth);
    //ERROR: PHP Fatal error:  Uncaught Error: Class "MinishlinkWebPushWebPush" not found in /home/<USER>/domains/<MY_DOMAIN>/public_html/push/subscription.php

    $webPush = new /Minishlink/WebPush/WebPush($auth);

    $webPush = new Minishlink/WebPush/WebPush($auth);


    use MinishlinkWebPushWebPush;
    $webPush = new WebPush($auth);
    //ERROR: PHP Parse error:  syntax error, unexpected token "use" in /home/<USER>/domains/<MY_DOMAIN>/public_html/push/subscription.php

    use MinishlinkWebPushWebPush;
    $webPush = new WebPush($auth);
    //ERROR: PHP Parse error:  syntax error, unexpected token "use" in /home/<USER>/domains/<MY_DOMAIN>/public_html/push/subscription.php

    use /Minishlink/WebPush/WebPush;
    $webPush = new WebPush($auth);
    //ERROR: PHP Parse error:  syntax error, unexpected token "use" in /home/<USER>/domains/<MY_DOMAIN>/public_html/push/subscription.php

    use Minishlink/WebPush/WebPush;
    $webPush = new WebPush($auth);
    //ERROR: PHP Parse error:  syntax error, unexpected token "use" in /home/<USER>/domains/<MY_DOMAIN>/public_html/push/subscription.php




    // general success variable
    $success = true;


    // build response object
    $response = (object) ['success' => $success, 'data' => (object) []];


    // return response
    echo json_encode($response);


    //--> without dependency it returns {success: true, data: {}}

}


php-mysqli: how to pass multidimensional array to bind_param()

I have an array:

$bindParamsArray = Array
(
    [0] => Array
        (
            [name] => Alex1
            [email] => [email protected]
            [city] => Moscow
        )

    [1] => Array
        (
            [name] => Marie
            [email] => [email protected]
            [city] => London
        )
    [2] => Array
        (
            [name] => Bob
            [email] => [email protected]
            [city] => Berlin
        )
)
$chunked_array = array_chunk($data, 100);
$query = "INSERT INTO posts (`name`,`email`,`city`) VALUES(?,?,?) ";
    $query .= " ON DUPLICATE KEY UPDATE email = VALUES(email), city= VALUES(city)";
    foreach($chunked_array as $array)
    {
        $stmt = $mysqli->prepare($query);
        foreach($array as $row)
        {
            $stmt->bind_param("sss", $row['name'], $row['email'], $row['city']);
            $stmt->execute();
        }

Here I bind inside the foreach loop, it is bad.
How can I do smth like this: $stmt->bind_param("sss", ...$bindParamsArray); and rewrite

foreach($array as $row)
        {
            $stmt->bind_param("sss", ...$bindParamsArray);
            
        } 
         $stmt->execute();

Query like this must be executed:

$query = "INSERT INTO posts (`name`,`email`,`city`) VALUES(?,?,?) ON DUPLICATE KEY UPDATE email = VALUES(email), city= VALUES(city) VALUES(name1, email1, city1),VALUES(name2, email2, city2),VALUES(name1, email3, city3);

Thank You!

SQLSTATE[23000]: Integrity constraint violation: 1048 Column ’employee_signature’ cannot be null

I am facing an issue with submitting signature data to the database in my Laravel application. The peculiar thing is that this problem only occurs when I have authentication enabled. When I remove the authentication middleware from the routes, everything works as expected.

Here is the relevant Blade code for the signature inputs:

<div class="row">
    <!-- Employee Signature -->
    <div class="col-md-6">
        <div class="form-group">
            <label for="employee_signature">Employee Signature</label>
            <div class="card">
                <div class="card-body">
                    <canvas id="employee_signature" style="width: 100%; height: 200px;"></canvas>
                </div>
            </div>
            <button type="button" id="clear_employee_signature" class="btn btn-secondary mt-2">Clear</button>
            <input type="hidden" id="employee_signature_data" name="employee_signature">
        </div>
    </div>
    <!-- Customer Signature -->
    <div class="col-md-6">
        <div class="form-group">
            <label for="customer_signature">Customer Signature</label>
            <div class="card">
                <div class="card-body">
                    <canvas id="customer_signature" style="width: 100%; height: 200px;"></canvas>
                </div>
            </div>
            <button type="button" id="clear_customer_signature" class="btn btn-secondary mt-2">Clear</button>
            <input type="hidden" id="customer_signature_data" name="customer_signature">
        </div>
    </div>
</div>
<div class="form-group">
    <label for="image_draw">Damage</label>
    <div class="card">
        <div class="card-body">
            <canvas id="image_draw" style="width: 100%; height: 470px;"></canvas>
        </div>
    </div>
    <button type="button" id="clear_image_draw" class="btn btn-secondary mt-2">Clear</button>
    <input type="hidden" id="image_draw_data" name="image_draw">
</div>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script>
window.onload = function () {
    var employeeSignatureCanvas = document.getElementById('employee_signature');
    var customerSignatureCanvas = document.getElementById('customer_signature');
    var imageDrawCanvas = document.getElementById('image_draw'); 

    [employeeSignatureCanvas, customerSignatureCanvas, imageDrawCanvas].forEach(canvas => {
        canvas.width = canvas.offsetWidth;
        canvas.height = canvas.offsetHeight;
    });

    var employeeSignaturePad = new SignaturePad(employeeSignatureCanvas, {penColor: 'red', minWidth: 1, maxWidth: 1});
    var customerSignaturePad = new SignaturePad(customerSignatureCanvas, {penColor: 'red', minWidth: 1, maxWidth: 1});
    var imageDrawPad = new SignaturePad(imageDrawCanvas, {penColor: 'red', minWidth: 10, maxWidth: 10});

    document.getElementById('clear_employee_signature').addEventListener('click', function () {
        employeeSignaturePad.clear();
    });
    document.getElementById('clear_customer_signature').addEventListener('click', function () {
        customerSignaturePad.clear();
    });
    document.getElementById('clear_image_draw').addEventListener('click', function () {
        imageDrawPad.clear();
        imageDrawCanvas.getContext('2d').drawImage(image, 0, 0, imageDrawCanvas.width, imageDrawCanvas.height);
    });

    document.querySelector('form').addEventListener('submit', function (e) {
        var employeeSignatureData = employeeSignaturePad.toDataURL();
        var customerSignatureData = customerSignaturePad.toDataURL();
        var imageDrawData = imageDrawPad.toDataURL(); 

        document.getElementById('employee_signature_data').value = employeeSignatureData;
        document.getElementById('customer_signature_data').value = customerSignatureData;
        document.getElementById('image_draw_data').value = imageDrawData;

        if (employeeSignaturePad.isEmpty() || customerSignaturePad.isEmpty() || imageDrawPad.isEmpty()) {
            e.preventDefault();
            alert('Please provide both signatures and draw on the image.');
        }
    });
};

$(function() {
    var employees = @json(array_map(function($employee) { return $employee['name']; }, $employees));
</script>

web.php

use IlluminateSupportFacadesRoute;
use AppHttpControllersTicketController;
use AppHttpControllersAuthLoginController;

// Login routes
Route::get('/login', [LoginController::class, 'showLoginForm'])->name('login');
Route::post('/login', [LoginController::class, 'login']);
Route::post('/logout', [LoginController::class, 'logout'])->name('logout');

// Authenticated routes
Route::middleware(['auth'])->group(function () {
    // Ticket routes
    Route::get('/', [TicketController::class, 'index']);
    Route::get('/add-ticket', [TicketController::class, 'create']);
    Route::post('/add-ticket', [TicketController::class, 'store']); 

    // Ticket specific routes
    Route::prefix('ticket')->group(function () {
        Route::get('/{id}', [TicketController::class, 'show']);
        Route::get('/{id}/pdf', [TicketController::class, 'generatePDF']);
        Route::put('/{id}', [TicketController::class, 'updateStatus']);
        Route::put('/{id}/report', [TicketController::class, 'updateReport']);
    });

    // Home route
    Route::get('/home', [TicketController::class, 'index'])->name('home');
});

TicketController

    public function store(Request $request)
{
    // Log the request data
    Log::info('Request data:', $request->all());

    $ticket = new Ticket;
    $ticket->full_name = $request->full_name;
    $ticket->cpr = $request->cpr;
    $ticket->password = $request->password;
    $ticket->mobile_no = $request->mobile_no;
    $ticket->invoice_no = $request->invoice_no;
    $ticket->products_with_issue = $request->products_with_issue;
    $ticket->issue_description = $request->issue_description;
    $ticket->received_by = $request->received_by;
    $ticket->assigned_to = $request->assigned_to;
    $ticket->employee_signature = $request->employee_signature;
    $ticket->customer_signature = $request->customer_signature;
    $ticket->image_draw = $request->image_draw;
    $ticket->save();

    return redirect('/add-ticket')->with('status', 'Ticket added successfully!');
}

Issue with webpage URL

I am facing a URL issue in my PHP website. There are 2 URLs in a single line as following example.

www.xyz.com/data-services.php/data.php

I am facing this issue throughout the website and google also counts this as a page error.

It will be great if anyone can provide solution to resolve this.

I tried to make redirects via htaccess but there are more than 2000 pages. If I can find out root of the issue, it will save my ample time.

WebView App crashes when clicking on Data Table Plugin export button

Hi i have a website using Data Tables plugin to show and export data in different formats like excel, csv and pdf. The website is running perfectly fine and buttons to export is also working. Now i have created WebView for the website, but whenever i click the export buttons from Data Tables plugin, the app crashes. I have given android downloader and permissions and have attached some screenshots of the code.
Using JQuery for Data Tables creation in website.

Plugin

code Jquery datatable implement

code webview

code webview android downloader.

I am new to webview creation, so can you also explain the issue and solution. I want the android webview to work perfectly fine, the buttons to download the data exactly like in my website.

Is it possible to have emojis in mySQL table names?

Let’s say if I’m making a website where I let people using emojis in their username, and I will have a table for each user to store their info/profiles/etc.., and the name of will be the same as their username.

I have no problem storing emojis or any special character into a table as data.

The character set and collation are both set utf8mb4 for my database, and I also have “CHARSET=utf8mb4” statement in my php mysqli_query function when I create the tables, it worked perfect for all kind of symbols, Chinese Characters, Japanese characters, even when I try to have these special character as part of the table names, no problem.

However, when I try to have emojis as part of the table names, whether I rename or create a table, mysql gives me a “#1300 – Invalid utf8mb4 character string” error.

Is it not possible to have emoji in the table names? If it is possible, how to do it?

Php, ZipArchive deletes an empty file?

here is a little code I wrote:

file_put_contents('a.upl', '');
try
{
    $x = new ZipArchive();
    $x->open('a.upl');
}
catch(Exception $e)
{
    echo $e->getMessage();
}

it throws a ZipArchive::open(): Using empty file as ZipArchive is deprecated message, which is not surprising.
What suprising is, this a.upl file gets deleted, which is a little bit strange. Why does it do that? And how to prevent this “x-files, magic”?

Dynamic insertion of elements into the array without enforcing a specific order

I have 3 input requests which is

$inputValues = array(
   'communication_text' => $request->text,
   'mms_image' => $request->mms_image,
   'communication_text2' => $request->text2
);

I want to insert the data inside into the following array:

$messageSegments = array();

foreach ($inputValues as $inputName => $inputValue) {
            // Check if the input value is not empty
    if (!empty($inputValue)) {
                // Add message segment based on input type
          if ($inputName === 'mms_image') {
              $messageSegments[] = array(
              "contentId" => basename($inputValue),
              "contentType" => "image/jpeg",
              "contentUrl" => $inputValue
             );
          } else {
             $messageSegments[] = array("text" => $inputValue);
          }
      }
   }

It always inside the data in specific order into $messageSegments array. How can I make it dynamic means if mms_image comes first , communication_text2 comes second, $messageSegments array should also be in that order as my form element is a draggable. User can change $request by dragging and $messageSegments array content also in that order?

How to send direct email in Flutter

I have a Flutter web contact page and I want to send an e-mail directly, but the existing packages do not work on the web. Does anyone have any ideas on this issue or can someone who has done this before help?

Current packages do not work on the web

Phpmyadmin showing php code instead of website

I am using Ubuntu 22.04.4 LTS and PHP 8.2.16 (cli). I successfully installed phpmyadmin after setting up apache2 & even gave the conf file path. But PHP is not working properly and So far my apache2, php, and mysql are working fine except phpmyadmin… Whenever I run this:

https://www.<domain-name>.com/phpmyadmin/

I am left with this on my browser:

<?php

declare(strict_types=1);

use PhpMyAdminRouting;

if (! defined('ROOT_PATH')) {
    // phpcs:disable PSR1.Files.SideEffects
    define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR);
    // phpcs:enable
}

global $route, $containerBuilder;

require_once ROOT_PATH . 'libraries/common.inc.php';

$dispatcher = Routing::getDispatcher();
Routing::callControllerForRoute($route, $dispatcher, $containerBuilder);

I searched about this issue & the most common answer was to install libapache2-mod-php8.1 that’s what I tried to do but I encountered the following:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 libapache2-mod-php8.1 : Depends: php8.1-common (= 8.1.2-1ubuntu2.14) but 8.1.27-2+clp-jammy is to be installed
E: Unable to correct problems, you have held broken packages.

As I am using php8.2 in my system I also tried to install libapache2-mod-php8.2 but got the following error:

E: Package 'libapache2-mod-php8.2' has no installation candidate

I also tried re-installing phpmyadmin but nothing worked.

Also when I tried to remove all PHP & reinstall only the necessary ones with the following command:

apt-get --purge remove php-common

or

sudo apt install php8.1-common=8.1.2-1ubuntu2.14

I get the following error. (I am using SSH & have a VPS Hosting along with CloudPanel)

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
php8.1 is already the newest version (8.1.27-2+clp-jammy).
php8.1-common is already the newest version (8.1.27-2+clp-jammy).
0 upgraded, 0 newly installed, 0 to remove and 9 not upgraded.
root@srv480865:~# sudo apt install php8.1-common=8.1.2-1ubuntu2.14
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  apt-show-versions dbconfig-common dbconfig-mysql fail2ban fonts-droid-fallback fonts-noto-mono ghostscript gifsicle gsfonts
  icc-profiles-free imagemagick-6-common iotop javascript-common jpegoptim libaom3 libapt-pkg-perl libarchive-tools
  libavahi-client3 libavahi-common-data libavahi-common3 libc-client2007e libcups2 libdav1d5 libde265-0 libevent-2.1-7
  libfftw3-double3 libgs9 libgs9-common libheif1 libidn12 libijs-0.35 libjbig2dec0 libjemalloc2 libjs-bootstrap4 libjs-codemirror
  libjs-jquery libjs-jquery-mousewheel libjs-jquery-timepicker libjs-jquery-ui libjs-popper.js libjs-sizzle libjs-sphinxdoc
  libjs-underscore liblcms2-2 liblqr-1-0 libltdl7 liblua5.1-0 liblzf1 libmagickcore-6.q16-6 libmagickwand-6.q16-6 libmcrypt4
  libonig5 libopenjp2-7 libossp-uuid16 libpaper-utils libpaper1 libsensors-config libsensors5 libwebpdemux2 libwebpmux3 libx265-199
  libxmlrpc-epi0 libzip4 lua-bitop lua-cjson memcached mlock nginx node-jquery optipng php-google-recaptcha php-mariadb-mysql-kbs
  php-nikic-fast-route php-phpmyadmin-motranslator php-phpmyadmin-shapefile php-phpmyadmin-sql-parser php-phpseclib php-psr-cache
  php-psr-container php-psr-log php-symfony-cache php-symfony-cache-contracts php-symfony-config php-symfony-dependency-injection
  php-symfony-deprecation-contracts php-symfony-expression-language php-symfony-filesystem php-symfony-polyfill-php80
  php-symfony-polyfill-php81 php-symfony-service-contracts php-symfony-var-exporter php-tcpdf php-twig php-twig-i18n-extension
  php7.1 php7.1-bcmath php7.1-cli php7.1-common php7.1-curl php7.1-fpm php7.1-gd php7.1-imap php7.1-intl php7.1-json
  php7.1-mbstring php7.1-mcrypt php7.1-mysql php7.1-opcache php7.1-readline php7.1-soap php7.1-sqlite3 php7.1-xml php7.1-xmlrpc
  php7.1-xsl php7.1-zip php7.2 php7.2-bcmath php7.2-cli php7.2-common php7.2-curl php7.2-fpm php7.2-gd php7.2-imap php7.2-intl
  php7.2-json php7.2-mbstring php7.2-mysql php7.2-opcache php7.2-readline php7.2-soap php7.2-sqlite3 php7.2-xml php7.2-xmlrpc
  php7.2-xsl php7.2-zip php7.3 php7.3-bcmath php7.3-cli php7.3-common php7.3-curl php7.3-fpm php7.3-gd php7.3-imap php7.3-intl
  php7.3-json php7.3-mbstring php7.3-mysql php7.3-opcache php7.3-readline php7.3-soap php7.3-sqlite3 php7.3-xml php7.3-xmlrpc
  php7.3-xsl php7.3-zip php7.4 php7.4-bcmath php7.4-cli php7.4-common php7.4-curl php7.4-fpm php7.4-gd php7.4-imap php7.4-intl
  php7.4-json php7.4-mbstring php7.4-mysql php7.4-opcache php7.4-readline php7.4-soap php7.4-sqlite3 php7.4-xml php7.4-xmlrpc
  php7.4-xsl php7.4-zip php8.0 php8.0-bcmath php8.0-cli php8.0-common php8.0-curl php8.0-fpm php8.0-gd php8.0-imap php8.0-intl
  php8.0-mbstring php8.0-mysql php8.0-opcache php8.0-readline php8.0-soap php8.0-sqlite3 php8.0-xml php8.0-xsl php8.0-zip php8.2
  php8.2-bcmath php8.2-cli php8.2-common php8.2-curl php8.2-fpm php8.2-gd php8.2-imap php8.2-intl php8.2-mbstring php8.2-mysql
  php8.2-opcache php8.2-readline php8.2-soap php8.2-sqlite3 php8.2-xml php8.2-xsl php8.2-zip php8.3 php8.3-bcmath php8.3-cli
  php8.3-common php8.3-curl php8.3-fpm php8.3-gd php8.3-imap php8.3-intl php8.3-mbstring php8.3-mysql php8.3-opcache
  php8.3-readline php8.3-soap php8.3-sqlite3 php8.3-xml php8.3-xsl php8.3-zip poppler-data pwgen python3-pyinotify rclone
  redis-server redis-tools sqlite3 sysstat unzip uuid varnish whois zip
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  cloudpanel php-curl php-gd php-json php-mbstring php-mysql php-zip php8.1 php8.1-bcmath php8.1-cli php8.1-curl php8.1-fpm
  php8.1-gd php8.1-imap php8.1-intl php8.1-mbstring php8.1-mysql php8.1-opcache php8.1-readline php8.1-soap php8.1-sqlite3
  php8.1-xml php8.1-xsl php8.1-zip phpmyadmin
The following packages will be DOWNGRADED:
  php8.1-common
0 upgraded, 0 newly installed, 1 downgraded, 25 to remove and 9 not upgraded.
Need to get 0 B/1,127 kB of archives.
After this operation, 357 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 158292 files and directories currently installed.)
Removing cloudpanel (2.4.1-1+clp-jammy) ...
This account is currently not available.
dpkg: error processing package cloudpanel (--remove):
 installed cloudpanel package pre-removal script subprocess returned error exit status 1
dpkg: too many errors, stopping
Errors were encountered while processing:
 cloudpanel
Processing was halted because there were too many errors.
E: Sub-process /usr/bin/dpkg returned an error code (1)

My php8.1 & php8.1-common is already updated:

php8.1 is already the newest version (8.1.27-2+clp-jammy).
php8.1-common is already the newest version (8.1.27-2+clp-jammy).

I have added ppa:ondrej/php, but these are the list of repositories:

deb http://in.archive.ubuntu.com/ubuntu/ jammy main restricted
deb http://in.archive.ubuntu.com/ubuntu/ jammy-updates main restricted
deb http://in.archive.ubuntu.com/ubuntu/ jammy universe
deb http://in.archive.ubuntu.com/ubuntu/ jammy-updates universe
deb http://in.archive.ubuntu.com/ubuntu/ jammy multiverse
deb http://in.archive.ubuntu.com/ubuntu/ jammy-updates multiverse
deb http://in.archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse
deb http://in.archive.ubuntu.com/ubuntu/ jammy-security main restricted
deb http://in.archive.ubuntu.com/ubuntu/ jammy-security universe
deb http://in.archive.ubuntu.com/ubuntu/ jammy-security multiverse
deb https://ppa.launchpadcontent.net/ondrej/apache2/ubuntu/ jammy main
deb https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu/ jammy main
deb [arch=amd64] https://repository.monarx.com/repository/ubuntu-jammy/ jammy main

Honestly, I am an Ubuntu noob & can’t figure out how to fix it. How do I resolve it?