having an error while creating automatic paper generator software on php

Error is

Fatal error: Uncaught mysqli_sql_exception: Unknown database ‘aqpg_db’ in C:xampphtdocsaqpgclassesDBConnection.php:18 Stack trace: #0 C:xampphtdocsaqpgclassesDBConnection.php(18): mysqli->__construct(‘localhost’, ‘root’, ”, ‘aqpg_db’) #1 C:xampphtdocsaqpgclassesSystemSettings.php(8): DBConnection->__construct() #2 C:xampphtdocsaqpgclassesSystemSettings.php(229): SystemSettings->__construct() #3 C:xampphtdocsaqpgconfig.php(9): require_once(‘C:xampphtdocs…’) #4 C:xampphtdocsaqpgindex.php(1): require_once(‘C:xampphtdocs…’) #5 {main} thrown in C:xampphtdocsaqpgclassesDBConnection.php on line 18)

code is :

<?php
if(!defined('DB_SERVER')){
    require_once("../initialize.php");
}
class DBConnection{

    private $host = DB_SERVER;
    private $username = DB_USERNAME;
    private $password = DB_PASSWORD;
    private $database = DB_NAME;
    
    public $conn;
    
    public function __construct(){

        if (!isset($this->conn)) {
            
            $this->conn = new mysqli($this->host, $this->username, $this->password, $this->database);
            
            if (!$this->conn) {
                echo 'Cannot connect to database server';
                exit;
            }            
        }    
        
    }
    public function __destruct(){
        $this->conn->close();
    }
}

?>

Implement server side rendering in laravel ( without any js framework)

My task is to improve lcp score (web vitals). Google is recomending that lcp score can be improve by server side rendering .My question is simple How can i do server side rendering in laravel. I am not using any js framework etc vue or react. My web site is totally based on laravel. Means Views are in blade template. Application is totally MVC based. Now i am confused in two things What is actually server side rendering in laravel ? And how can we do server side rendering in laravel. And if my question is wrong then plz clear my concept.`

I want to change picture but not changed

I have a faced a problem during building a web application using laravel, the logo is exist in the app and appear on login.
The problem is when i try to change logo or delete it and upload new logo still appear the first logo does not change
I have run php artisan cache:clear but same problem
but when i call a picture using a url it works perfectly

Any advice please

keep always logged in using php

this is my code and I want that user stay logged in until he log out from website,

<?php 
session_start();
include_once "config.php";
$email = mysqli_real_escape_string($conn, $_POST['email']);
$password = mysqli_real_escape_string($conn, $_POST['password']);
if(!empty($email) && !empty($password)){
    $sql = mysqli_query($conn, "SELECT * FROM users WHERE email = '{$email}'");
    if(mysqli_num_rows($sql) > 0){
        $row = mysqli_fetch_assoc($sql);
        $user_pass = md5($password);
        $enc_pass = $row['password'];
        if($user_pass === $enc_pass){
            $status = "Active now";
            $sql2 = mysqli_query($conn, "UPDATE users SET status = '{$status}' WHERE unique_id = {$row['unique_id']}");
            if($sql2){
                $_SESSION['unique_id'] = $row['unique_id'];
    
                echo "success";
            }else{
                echo "Something went wrong. Please try again!";
            }
        }else{
            echo "Email or Password is Incorrect!";
        }
    }else{
        echo "$email - This email not Exist!";
    }
}else{
    echo "All input fields are required!";
}

?>

I want that user stay logged in after closing the browser.

How to add multiple products to line_items in Cashier/Stripe? (As array of hashes)

I’m trying to create a Stripe checkout session, but I’m having trouble with the line_items part. When I want to checkout 1 product, there is no problem, but when I want to checkout multiple items I get invalid array back from the Stripe API.

The Stripe documentation about checkout session line_items tells me line_items needs to be an ‘array of hashes’ and I believe that’s where I run into the problem.

$items = array();

   foreach($cart as $itemInCart){
        array_push($items, array(
            'price' => $itemInCart['product']['stripeData']['price']['id'],
            'quantity' => $itemInCart['quantity'],
        ));      
    }

When I dd($items) after running the code above:

^ array:2 [▼
  0 => array:2 [▼
    "price" => "price_1LkRKDGA4B3lyBQM1AyPTB3g"
    "quantity" => 1
  ]
  1 => array:2 [▼
    "price" => "price_1LkRLsGA4B3lyBQMgZvay5zZ"
    "quantity" => 1
  ]
]

But if I’m not mistaken, Stripe expects it to be:

^ array:2 [▼
  [▼
    "price" => "price_1LkRKDGA4B3lyBQM1AyPTB3g"
    "quantity" => 1
  ],
  [▼
    "price" => "price_1LkRLsGA4B3lyBQMgZvay5zZ"
    "quantity" => 1
  ]
]

The amount of items in $cart may vary, so I can’t ‘hardcode’ the list_items; it needs to be dynamic.

 $checkout_session = $stripe->checkout->sessions->create([
            'payment_method_types' => ['card'],
            'line_items' =>  $items, // <-- Here is the $items variable
            'mode' => 'payment',
            'automatic_tax' => [
                'enabled' => true,
            ],
            'shipping_options' => [
                'shipping_rate_data' => [
                    'display_name' => 'Bezorging door PostNL',
                    'type' => 'fixed_amount',
                    'delivery_estimate' => [
                        'maximum' => 5,
                        'minimum' => 2,
                    ],
                    'fixed_amount' => [
                        'amount' => 6.25,
                        'currency' => 'eur',
                    ],
                    'tax_behavior' => 'inclusive',
                ],
            ],
            'success_url' => route('checkout.success'),
            'cancel_url' => route('checkout.cancel'),
        ]);

Is there a way to remove the keys from the array to make it an array of hashes, or do I need to do something else?

Preserving session form input data across different domains

I want to preserve this data –
you will see screenshot here – in session and show here different url.

The main thing is that, these 2 folder is in the same public_html, just I want to show what I input in the first domain to the second, but when I see in the session when URL changing data is losing and can is any solution?

*you can test this all here: https://freshistjuice.com/lp/ipad-pro-v2/index.php – and you will understand more (field any test data and click the button you will see this data not transferring here: https://everycookingstep.co.uk/lp/juice-blender-lp/checkout.php

How can I change path as root dir (PHP / Apache )?

Nowadays I use path to file (in DB) like this

“/files/person_1/awatar.png” – it works , file_get_content (“/files/person_1/awatar.png”) = true – is ok!

But now I changed my web server and … In PHP I can see “directory not found exception”

Path on server: /var/www/public_html/new_service_xxxxx/files/awatar.png
In PHP I have “/” as first character, I don’t want to change it.

What I should change ?

<VirtualHost *:80>
    ServerName test.new_service_xxxxx.pl
    ServerAlias www.new_service_xxxxx.pl
    DocumentRoot /var/www/public_html/new_service_xxxxx


    <Directory /var/www/public_html/new_service_xxxxxk>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <IfModule mod_dir.c>
        DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm index.php5
    </IfModule>

</VirtualHost>

Import excel using the latest PHPSpreadsheet version but parse an error (500 Internal Server Error)

I want to import excel files to read its content but it shows me an error that says “500 Internal Server Error”. My PHP version that I’m currently using is PHP Version 7.4.29. Is there a problem with the version I’m using in XAMPP or Spreadsheet?

My PHP sourcecode for PHPSpreadsheet to read excel:

use PhpOfficePhpSpreadsheetSpreadsheet;
use PhpOfficePhpSpreadsheetIOFactory;

public function readExcelSpreadsheet() {
    require '../PHPSpreadsheet/vendor/autoload.php';
    $arr = [];
    $arr['items'] = [];
    $fileName = $_FILES['importExcelSpreadsheet']['name'];
    $importPath = "../PHPSpreadsheet/import/";
    
    if (
        move_uploaded_file($_FILES['importExcelSpreadsheet']['tmp_name'], 
        "{$importPath}{$fileName}")
        ) {
      if (isset($fileName)) {
        $reader = PhpOfficePhpSpreadsheetIOFactory::createReaderForFile("{$importPath}{$fileName}");
        $spreadsheet = PhpOfficePhpSpreadsheetIOFactory::load("{$importPath}{$fileName}");
        $data = $spreadsheet->getActiveSheet()->toArray();
  
        foreach ($data as $row) {
          $items = [
            'name'  => $row['0'],
            'email' => $row['1']
          ];
          array_push($arr['items'], $items);
        }      
        return $arr;
      }
    }
  }

Here’s my AJAX request:

$(document).on("change", "#primary-btn-import-for-import-csv", function () {
  if ($("#primary-btn-import-for-import-csv")[0].files.length != 0) {
    $("#primary-email-lists-for-import-csv").multiselect("rebuild");

    let form = new FormData();
    form.append("importExcelSpreadsheet", $("#primary-btn-import-for-import-csv")[0].files[0]);

    $.ajax({
      url: baseUrlAction() + "?btn=readExcelSpreadsheet",
      type: "POST",
      dataType: "JSON",
      data: form,
      contentType: false,
      processData: false,
      cache: false,
      error: function (error) {
        console.log(error.responseText);
      },
      success: function (response) {
        let options;
        for (let i = 0; i < response.length; i++) {
          options += 
            '<option value="' + response[i].name + ";" + response[i].email + '">' +
              response[i].email +
            "</option>";
        }
        $("#primary-email-lists-for-import-csv").html(options);
        $("#primary-email-lists-for-import-csv").multiselect("rebuild");
        $("#primary-email-lists-for-import-csv").multiselect("refresh");
      },
    });
  }
});

In PHP, how can I select 1 of 3 child classes without conditional statements

I have a task where I need to output an object of class Honda or BMW or Tesla, all of which extend the abstract class Car. The output should be based on what input is entered by the user, but no conditional statements are allowed in any part of the code (if-else, switch-case, ternary).

The input options are “Japan”, “Germany” and “America”, which should respectively output an object of Honda, BMW or Tesla.

What I did initially was try to use ternary operators, but I was told to rework it as ternary operators are still considered conditional.

hon = new Honda;
bmw = new BMW;
tes = new Tesla;

newH = hon->objectify();
newB = bmw->objectify();
newT = tes->objectify();

myCar = newH ?: newB ?: newT;
return myCar;

This was what I did, where objectify() is basically an abstract function implemented differently by each child class, returning null if the input doesn’t match, or an object of itself if the input matches.

This submission was rejected. Please what’s a better way to make this work?

Short and Long Discription in Woocommerce Product Category

I want to have a short description and a long description on all my product category (Archive) pages. I have been able to move the product archive description to the bottom of the page using the code below:

// move Product category description to bottom of pages

remove_action( 'woocommerce_archive_description', 'woocommerce_taxonomy_archive_description', 10 );
add_action( 'woocommerce_after_shop_loop', 'woocommerce_taxonomy_archive_description', 100 );

What I also need is a short description to display at the top of every product archive page, but I have no idea how to do this. My current theme (OceanWP) doesn’t give an option to have short and long descriptions on the product archive. What is the way around this?

how to remove whitespaces from each beginning of a php string

How to execute align left for text?
actual text

Resolved
        devic_name: my_device_name - device title if available, if not - fqhost or remote ip address
        device_url : http://test/#/groups/de5a4eb96125d63a6fb330d6afbf44fbe9077a0ba796de1f40e28f70d8489362 - direct url to the device page on the qbee platform
        device_link: [my_device_name](http://test/#/groups/de5a4eb96125d63a6fb330d6afbf44fbe9077a0ba796de1f40e28f70d8489362) - html construct my_device_name
        title: devpi1 - device title which can be set on the device page
        fqhost: devpi1 - the fully qualified name of the host
        remoteaddr: ip: 188.95.241.148 - remove IP addres of the device
        alert_name: parser - name of the alert
        alert_url: http://test/some_path/alert/837f2ad5-7b42-4434-87ea-b4e1793dc212 - direct url to the alert page
        alert_link: [parser](http://test/some_path/alert/837f2ad5-7b42-4434-87ea-b4e1793dc212) - html construct parser

expected

Resolved
devic_name: my_device_name - device title if available, if not - fqhost or remote ip address
device_url : http://test/#/groups/de5a4eb96125d63a6fb330d6afbf44fbe9077a0ba796de1f40e28f70d8489362 - direct url to the device page on the qbee platform
device_link: [my_device_name](http://test/#/groups/de5a4eb96125d63a6fb330d6afbf44fbe9077a0ba796de1f40e28f70d8489362) - html construct my_device_name
title: devpi1 - device title which can be set on the device page
fqhost: devpi1 - the fully qualified name of the host
remoteaddr: ip: 188.95.241.148 - remove IP addres of the device
alert_name: parser - name of the alert
alert_url: http://test/some_path/alert/837f2ad5-7b42-4434-87ea-b4e1793dc212 - direct url to the alert page
alert_link: [parser](http://test/some_path/alert/837f2ad5-7b42-4434-87ea-b4e1793dc212) - html construct parser

How to add minutes value in for loop PHP?

I have these for loop code that loop time and increase minute by 20+ minutes.

But I want to include also the starting time. Somehow it’s missing in the output.

My current code :

$slot_count = 5;

$start = strtotime("08:00");

for( $i=0; $i<$slot_count; $i++ )
{
    $start  = $start;
    $end_new = date("H:i:s", strtotime('+20 minutes', $start));  
    $start  = strtotime($end_new);

    echo ''.$end_new.'<br/>';
    
} 

Current output :

08:20:00
08:40:00
09:00:00
09:20:00
09:40:00

Expected output :

08:00:00
08:20:00
08:40:00
09:00:00
09:20:00
09:40:00