mysql gow can limk with my login to conect w external web [duplicate]

how can configur my login to mysql

Fatal error: Uncaught mysqli_sql_exception: Unknown database ‘login-php’ in C:xampphtdocsautenticacion.php:14 Stack trace: #0 C:xampphtdocsautenticacion.php(14): mysqli_connect(‘localhost’, ‘root’, Object(SensitiveParameterValue), ‘login-php’) #1 {main} thrown in C:xampphtdocsautenticacion.php on line 14

Ghostscript “gs” breaks imagick readImage for PDF

When everything is installed and setup regarding magick and if the Environment Variables path is also set, you should look at the installation folder which is usually located in C:Program Filesgsgs10.x .0bin. If there is no gs.exe and only gswin64.c.exe, copy that executable and change its name to gs.exe and readImage() will run the script.

With Laravel and php i have tried to convert pdf to png so i could use it for converting png image to zpl extension. Installing ghostscript for windows system didn’t help because file that are installed do not have proper name that class Imagick call and that name of executabel is “gs” and not “gswin64c”. Changing name help to solve problem and run ghostscript.

How to get custom variable price if bought in bulk (2x, 3x)

I want to have option to buy 2x or 3x product with discount (custom) price.
If chosen 2x or 3x all the attributes have same price.

The issue is that the custom price (e.g., 19.9) is not being applied to the cart item, and the base prices (price: “22.90”, regular_price: “34.90”) are still being used. This indicates that the custom price is not being properly passed to the server or applied to the cart item.

  1. Custom Price Not Applied:
    The custom price is sent to the server, but it is not being applied to the cart item.
    The base prices (price, regular_price, sale_price) are still being used.

  2. WooCommerce REST API Not Handling Custom Price:
    The WooCommerce REST API (/wp-json/wc/store/v1/batch) does not natively support custom prices. You need to handle this on the server side.

  3. JavaScript and PHP Integration:
    The JavaScript code sends the custom price to the server, but the PHP code is not properly applying it to the cart item.

To solve this problem, i need to:

  1. Ensure the Custom Price is Passed to the Server:
    The JavaScript code must send the custom price to the server when adding items to the cart.

  2. Apply the Custom Price to the Cart Item:
    Use WooCommerce hooks to override the product price when it is added to the cart.

  3. Retain the Custom Price in the Cart Session:
    Ensure the custom price is retained in the cart session after page refresh.

  4. Display the Custom Price in the Mini-Cart and Cart Page:
    Ensure the custom price is displayed correctly in the mini-cart and cart page.

My functions code:

function custom_pricing_options_html() {
    if (!is_product()) return;

    global $product;

    // Check if the product is simple or variable
    if (!$product->is_type('simple') && !$product->is_type('variable')) return;

    $product_id = $product->get_id();
    $currency = get_woocommerce_currency_symbol();

    // Get base prices
    $regular_price = $product->is_type('variable') 
        ? floatval($product->get_variation_regular_price('min')) 
        : floatval($product->get_regular_price());
    $sale_price = $product->is_type('variable') 
        ? floatval($product->get_variation_sale_price('min')) 
        : floatval($product->get_sale_price());

    // Get custom pricing options from ACF fields
    $price_option_2 = floatval(get_field('pricing_option_2', $product_id)) ?: 0;
    $price_option_3 = floatval(get_field('pricing_option_3', $product_id)) ?: 0;

    // Pricing options for 1x, 2x, and 3x
    $pricing_options = [
        1 => ['price' => $sale_price],
        2 => ['price' => $price_option_2],
        3 => ['price' => $price_option_3],
    ];

    ob_start();
    ?>

    <div class="pricing-container">
        <?php foreach ($pricing_options as $qty => $option) :
            if ($option['price'] <= 0) continue; // Skip empty values
        ?>
        <div class="pricing-option <?php echo $qty === 1 ? 'selected' : ''; ?>" 
            data-qty="<?php echo esc_attr($qty); ?>" 
            data-price="<?php echo esc_attr($option['price']); ?>" 
            data-currency-symbol="<?php echo esc_attr($currency); ?>">
    
            <div class="qty-discount-qty"><?php echo esc_html($qty); ?>x</div>
            <span class="qty-discount-price">
                <strong><?php echo esc_html($option['price'] . ' ' . $currency); ?></strong>
            </span>
            <div class="qty-discount-kos">per pair</div>
        </div>
        <?php endforeach; ?>
    </div>

    <!-- Hidden field to store the selected price -->
    <input type="hidden" id="custom_selected_price" name="custom_selected_price" value="<?php echo esc_attr($sale_price); ?>">
    
   
    <?php
    echo ob_get_clean();
}
add_action('woocommerce_before_add_to_cart_form', 'custom_pricing_options_html');

// Save the selected price in cart item data
add_filter('woocommerce_add_cart_item_data', 'update_sale_price_in_cart', 10, 2);
function update_sale_price_in_cart($cart_item_data, $product_id) {
    if (isset($_POST['custom_selected_price'])) {
        $selected_price = floatval($_POST['custom_selected_price']);
        error_log('Selected Price in Cart: ' . $selected_price); // Debug
        $cart_item_data['custom_price'] = $selected_price;
    }
    return $cart_item_data;
}

// Apply the custom price to the cart item
add_action('woocommerce_before_calculate_totals', 'apply_custom_price_to_cart', 20);
function apply_custom_price_to_cart($cart) {
    if (is_admin() && !defined('DOING_AJAX')) return;

    foreach ($cart->get_cart() as $cart_item_key => $cart_item) {
        if (isset($cart_item['custom_price'])) {
            $custom_price = floatval($cart_item['custom_price']);
            $cart_item['data']->set_price($custom_price); // Override base price
        }
    }
}

// Retain the custom price in the cart after page refresh
add_filter('woocommerce_get_cart_item_from_session', 'retain_custom_price_in_cart', 10, 2);
function retain_custom_price_in_cart($cart_item, $values) {
    if (isset($values['custom_price'])) {
        error_log('Retaining Custom Price: ' . $values['custom_price']); // Debug
        $cart_item['custom_price'] = $values['custom_price'];
    }
    return $cart_item;
}

// Display custom price in mini-cart and cart page
function display_custom_price_in_cart($price, $cart_item, $cart_item_key) {
    if (isset($cart_item['custom_price'])) {
        $price = wc_price($cart_item['custom_price']);
    }
    return $price;
}
add_filter('woocommerce_cart_item_price', 'display_custom_price_in_cart', 10, 3);
add_filter('woocommerce_cart_item_subtotal', 'display_custom_price_in_cart', 10, 3);

// AJAX Handler for Adding to Cart with Custom Price
add_action('wp_ajax_add_to_cart_with_custom_price', 'add_to_cart_with_custom_price');
add_action('wp_ajax_nopriv_add_to_cart_with_custom_price', 'add_to_cart_with_custom_price');
function add_to_cart_with_custom_price() {
    if (!isset($_POST['product_id']) || !isset($_POST['custom_price'])) {
        wp_send_json_error('Invalid request.');
    }

    $product_id = intval($_POST['product_id']);
    $quantity = intval($_POST['quantity']);
    $custom_price = floatval($_POST['custom_price']);

    // Add product to cart
    $cart_item_key = WC()->cart->add_to_cart($product_id, $quantity);

    if ($cart_item_key) {
        // Set custom price in cart item data
        WC()->cart->cart_contents[$cart_item_key]['custom_price'] = $custom_price;
        WC()->cart->set_session();

        // Recalculate totals to apply the custom price
        WC()->cart->calculate_totals();

        wp_send_json_success('Product added to cart.');
    } else {
        wp_send_json_error('Failed to add product to cart.');
    }
}

My javascript:


jQuery(document).ready(function ($) {
    const $body = $('body');
    const $pricingOptions = $('.pricing-option');
    const $customSelectedPrice = $('#custom_selected_price');
    const $addToCartButton = $('.single_add_to_cart_button');

    // Event delegation for pricing options
    $body
        .on('click', '.pricing-option', function () {
            $pricingOptions.removeClass('selected');
            $(this).addClass('selected');

            const qty = $(this).data('qty');
            const price = $(this).data('price');

            // Debug: Log the selected price
            console.log('Selected Price:', price);

            // Update the hidden input field
            $customSelectedPrice.val(price);

            duplicateVariationSelection(qty);
            updatePriceTotal();
            updateSimpleQuantity(qty);
            maybeDisableVariableAddToCartButton();
        })
        .on('click', '.qty-appended .filter-item-list li', function () {
            $(this).parents('.qty-appended').find('.filter-item-list li').removeClass('active');
            $(this).addClass('active');
            maybeDisableVariableAddToCartButton();
        })
        .on('click', '.product-type-variable .single_add_to_cart_button', function (e) {
            e.preventDefault();

            const selectedPrice = $customSelectedPrice.val();
            console.log('Price sent to server:', selectedPrice);

            if ($(this).hasClass('wc-variation-selection-needed') && $('.qty-appended').length > 0) {
                alert('Please select all variations before adding to cart.');
                return;
            }

            addAppendedItemsToCart(selectedPrice);
        });

    // Duplicate variations based on selected quantity
    function duplicateVariationSelection(qty) {
        if ($('.product-type-variable').length <= 0) return;

        const label = $('.variations .label label').first().text();
        const list = $('.variations .value ul.filter-item-list').clone().html().replace(/active/g, '');

        $('.qty-appended').remove(); // Remove previous appended rows

        for (let i = 2; i <= qty; i++) {
            $('.variations tbody').append(`
                <tr class="qty-appended qty-${i}">
                    <th class="label"><label>${label} ${i}</label></th>
                    <td><ul class="filter-item-list">${list}</ul></td>
                </tr>`);
        }

        maybeDisableVariableAddToCartButton();
    }

    // Enable/disable the "Add to Cart" button based on selected variations
    function maybeDisableVariableAddToCartButton() {
        const totalAppended = $('.qty-appended').length;
        const totalSelected = $('.filter-item-list li.active').length;

        $addToCartButton.prop('disabled', totalAppended + 1 !== totalSelected);
    }

    // Add items to the cart
    function addAppendedItemsToCart() {
        const attributeName = $('[data-attribute_name]').data('attribute_name');
        const variationData = $('[data-product_variations]').data('product_variations');
        const totalAppended = $('.qty-appended').length;
        const selectedPrice = $('.pricing-option.selected').data('price'); // Get selected price
        let cartData = [];
    
        let itemAttributeOriginal = $('table.variations tr:not(.qty-appended) li.active a').data('value');
    
        // Original selected variation.
        $.each(variationData, function (key, value) {
            if (value['attributes'][attributeName] === itemAttributeOriginal) {
                cartData.push({
                    path: '/wc/store/v1/cart/add-item',
                    method: 'POST',
                    headers: {
                        'Nonce': product_js_vars.woononce
                    },
                    body: {
                        id: value.variation_id,
                        quantity: 1,
                        custom_price: selectedPrice // Include custom price
                    }
                });
            }
        });
    
        // If multiple appended
        if ($('.qty-appended').length > 0) {
            for (let i = 1; i < totalAppended + 1; i++) {
                let counter = i + 1;
                const itemAttribute = $(`.qty-${counter} .filter-item-list li.active a`).data('value');
    
                $.each(variationData, function (key, value) {
                    if (value['attributes'][attributeName] === itemAttribute) {
                        cartData.push({
                            path: '/wc/store/v1/cart/add-item',
                            method: 'POST',
                            headers: {
                                'Nonce': product_js_vars.woononce
                            },
                            body: {
                                id: value.variation_id,
                                quantity: 1,
                                custom_price: selectedPrice // Include custom price
                            }
                        });
                    }
                });
            }
        }
    
        $.ajax({
            url: '/wp-json/wc/store/v1/batch',
            method: 'POST',
            dataType: 'json',
            headers: {
                'Nonce': product_js_vars.woononce
            },
            data: {
                requests: cartData
            },
            success: function (response) {
                console.log("Items added to cart:", response);
            },
            error: function (xhr) {
                console.error('Error adding item to cart:', xhr.responseJSON);
            }
        });
    }

    // Update the displayed price
    function updatePriceTotal() {
        const selectedOption = $('.pricing-option.selected');
        const price = selectedOption.data('price');
        const qty = selectedOption.data('qty');
        const percent = selectedOption.data('percent');
        const regular = selectedOption.data('regular');
        const currency = selectedOption.data('currency-symbol');

        const totalRegular = (regular * qty).toFixed(2);
        const totalPrice = (price * qty).toFixed(2);

        $('.price-placeholder').html(`
            <div class="variable-price-box">
                <div class="left-price-wrapper">
                    <div class="limited-offer-label">Quantity: ${qty}</div>
                    <div class="discount-badge-price">-${percent}% discount</div>
                </div>
                <div>
                    <del>${totalRegular} ${currency}</del>
                    <ins>${totalPrice} ${currency}</ins>
                </div>
            </div>`);
    }

    // Update quantity for simple products
    function updateSimpleQuantity(qty) {
        if ($('.product-type-variable').length > 0) return;
        $('form.cart .quantity input.qty').val(qty).trigger('change');
    }
});

How to test and share PHP and MySQL code together [closed]

I’m looking for an open-source online development environment or fiddle, similar to JSFiddle, that allows me to create and share small PHP and MySQL code snippets. My goal is to build proof-of-concept examples that I can share in Stack Overflow answers, where viewers can test the code live without needing to set up their own server environments.

Ideally, the tool should support both PHP scripts and MySQL queries, providing a quick and easy way to demonstrate server-side code and database interactions directly in the browser.

Does anyone know of a platform or tool that fits this use case, where I can generate and share these kinds of live demos without any server configuration?

Query with nulls and apostrophes returning syntax error using PDO bindParam (PHP) [duplicate]

I’ve been trying for hours to figure out what I’m doing wrong. The $trackName variable may include apostrophes. Also, some of the $subgenre and $mood variables may be NULL. This is my PHP code:

$sg2 = is_null($subgenre_2) ? NULL : $subgenre_2;
$sg3 = is_null($subgenre_3) ? NULL : $subgenre_3;
$sg4 = is_null($subgenre_4) ? NULL : $subgenre_4;
$sg5 = is_null($subgenre_5) ? NULL : $subgenre_5;

$md2 = is_null($mood_2) ? NULL : $mood_2;
$md3 = is_null($mood_3) ? NULL : $mood_3;

$query = "INSERT INTO `songs` (song_id, username, subgenre_1, subgenre_2, subgenre_3, subgenre_4, ";
$query .= "subgenre_5, mood_1, mood_2, mood_3, name, artist_name, active) ";
$query .= "VALUES ('" . $_SESSION['new_TK_data']['song-id'] . "', '" . $_SESSION['username'] ."', '";
$query .= $subgenre_1 . "', " . $sg2 . ", " . $sg3 . ", " . $sg4 . ", " . $sg5 . ", '";
$query .= $mood_1 . "', " . $md2 . ", " . $md3 . ", :name, '";
$query .= $_SESSION['new_TK_data']['artist_name'] . "', 1)";

$trackName = $_SESSION['new_TK_data']['name'];

$stmt = $pdo->prepare($query);
$stmt->bindParam(':name', $trackName, PDO::PARAM_STR);
$stmt->execute();    

This is what $query shows before binding:

INSERT INTO `songs` (song_id, username, subgenre_1, subgenre_2, subgenre_3, subgenre_4, subgenre_5, mood_1, mood_2, mood_3, name, artist_name, active) 
VALUES ('1peKZ91pGaS7QXzDBrICRy', 'romotony11', 'CONPNO', NEOCLA, SOLOPN, , , '6565', 4090, 1565, :name, 'Antonio Romo', 1)

This is the error I get:

Query failed: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘ , ‘6565’, 4090, 1565, ‘Twilight Mood’, ‘Antonio Romo’, 1)’ at line 1

I’m not sure if the error comes from the null values, or from the single quotes missing in some values than come from variables, or from something else. I’ve tried many different things without success. Any help will be appreciated!

Laravel Sanctum Email Verification Not Updating email_verified_at Field

I’m building an API using Laravel 10 with Sanctum for authentication, and I’m encountering an issue with email verification. After the user clicks the verification link, the email_verified_at field remains null.

This is my register component

import React from "react";
import { useNavigate } from "react-router-dom";

function Register() {
  const [name, setName] = React.useState("");
  const [email, setEmail] = React.useState("");
  const [password, setPassword] = React.useState("");
  const navigate = useNavigate();

  React.useEffect(() => {
    if (localStorage.getItem("token")) {
      navigate("/account");
      window.location.reload();
    }
  }, []);

  async function register() {
    const item = { name, email, password };

    let result = await fetch("http://localhost:8000/api/register", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        Accept: "application/json",
      },
      body: JSON.stringify(item),
    });

    const data = await result.json();

    if (result.ok) {
      alert("Please verify your email before logging in.");
      navigate("/login");
    } else {
      alert(data.message || "Error registering.");
    }
  }

  return (
    <div className="py-16">
      <div className="flex items-center flex-col justify-center gap-6">
        <div className="flex items-center justify-center">
          <h1>Register Form</h1>
        </div>

        <div className="flex items-center flex-col gap-5 justify-center">
          <input
            type="text"
            placeholder="Name"
            value={name}
            onChange={(e) => setName(e.target.value)}
          />
          <input
            type="email"
            placeholder="Email"
            value={email}
            onChange={(e) => setEmail(e.target.value)}
          />
          <input
            type="password"
            placeholder="Password"
            value={password}
            onChange={(e) => setPassword(e.target.value)}
          />
        </div>

        <div>
          <button onClick={register} className="border-2 border-black p-2">
            Register
          </button>
        </div>
      </div>
    </div>
  );
}

export default Register;

This is my auth controller

<?php

namespace AppHttpControllers;
use IlluminateValidationValidationException; //manually imported
use IlluminateSupportFacadesHash; //manually imported
use IlluminateHttpRequest;
use AppModelsUser; //manualy imported
use IlluminateAuthEventsVerified;
use IlluminateFoundationAuthEmailVerificationRequest;
use CarbonCarbon;
class AuthController extends Controller
{
    //

    public function verifyEmail(Request $request, $id, $hash)
    {
        $user = User::find($id);

        if (!$user) {
            return response()->json(['message' => 'User not found.'], 404);
        }


        if (!hash_equals(sha1($user->getEmailForVerification()), $hash)) {
            return response()->json(['message' => 'Invalid verification link.'], 400);
        }


        if ($user->email_verified_at) {
            return response()->json(['message' => 'Email already verified.']);
        }

        $user->email_verified_at = Carbon::now();
        $user->save();

        return response()->json(['message' => 'Email verified successfully.']);
    }
    public function resendEmailVerification(Request $request)
    {
        if ($request->user()->hasVerifiedEmail()) {
            return response()->json(['message' => 'Email already verified.']);
        }

        $request->user()->sendEmailVerificationNotification();

        return response()->json(['message' => 'Verification email sent.']);
    }

    public function register(Request $request)
    {
        $request->validate([
            'name' => 'required|string|max:255',
            'email' => 'required|string|email|unique:users',
            'password' => 'required|string|min:6'
        ]);

        $user = User::create([
            'name' => $request->name,
            'email' => $request->email,
            'password' => Hash::make($request->password)
        ]);


        $user->sendEmailVerificationNotification();



        $token = $user->createToken('auth_token')->plainTextToken;

        return response()->json(['token' => $token, 'user' => $user], 201);
    }

    public function login(Request $request)
    {
        $request->validate([
            'email' => 'required|email',
            'password' => 'required'
        ]);

        $user = User::where('email', $request->email)->first();

        if (!$user || !Hash::check($request->password, $user->password)) {
            return ["error" => "Invalid credentials"];
        }

        $token = $user->createToken('auth_token')->plainTextToken;

        return response()->json(['token' => $token, 'user' => $user]);
    }

    public function logout(Request $request)
    {
        $request->user()->tokens()->delete();

        return response()->json(['message' => 'Logged out']);
    }

    public function user(Request $request)
    {
        return response()->json($request->user());
    }



}

These are my api routes

<?php

use AppHttpControllersAuthController;
use AppHttpControllersDisplayController;
use AppHttpControllersOrderController;
use AppHttpControllersStripeController;
use IlluminateHttpRequest;
use IlluminateSupportFacadesRoute;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
    return $request->user();
});


Route::post("/login",[AuthController::class,"login"]);
Route::post("/register",[AuthController::class,"register"]);

Route::middleware('auth:sanctum')->post('/addOrder', [OrderController::class, 'addOrder']);

Route::middleware('auth:sanctum')->post('/pay', [StripeController::class, 'pay']);

Route::middleware('auth:sanctum')->get('/displayOrders', [DisplayController::class, 'displayOrders']);



Route::get('/email/verify/{id}/{hash}', [AuthController::class, 'verifyEmail'])
    ->middleware(['signed']) 
    ->name('verification.verify');

And these are my web routes

<?php

use IlluminateSupportFacadesRoute;
use IlluminateFoundationAuthEmailVerificationRequest;
use AppHttpControllersAuthController;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});


Route::get('/login', function () {
    return redirect('http://localhost:5173/login');
})->name('login');
Route::get('/email/verify/{id}/{hash}', [AuthController::class, 'verifyEmail'])
    ->middleware(['auth:sanctum', 'signed'])
    ->name('verification.verify');

I already made sure that the user model has the email verification thing enabled. Simply , after I receive the confirmation email on mailtrap and click the button I am getting redirected to the login page and then when checking the data base the “email_verified_at” entry is still empty… pls help

Is t possible to listen to multiple connections with ReactPHP truly async?

I need to start tcp server that accepts connections and for every connection creates websocket connection to another server, receives data from tcp, processes the data and sends it to WS

Data sent to tcp is being send continuously, so without truly async handling both tcp and ws, I have lost packets

I tried using reactphp/child-process, still child process needs to liste to stdin and WS, so the problem is the same

Im not proficient in reactPHP, am I doing something wrong or is it just impossible with this environment ?

Page name ‘Login’ is not working on WordPress

I have created a new page called Login (mysite.com/login) on my wordpress website but when I tried to access the page, it throws an error

This is all I see in the source

<html>
<head>
<meta name="color-scheme" content="light dark">
<meta charset="utf-8">
</head>
<body>
<pre>{"error":"not found"}</pre>
<div class="json-formatter-container"></div>
</body>
</html>

I tried disabling and enabling the plugins and nothing worked.

Any help would be appreciated.

Autoupgrade prestashop 1.7.8.8 to 8.1.7 – how to solve error with “upgradeDB” step?

I try to upgrade Prestashop from 1.7.8.8 to 8.1.7. I decided to use autoupgrade via cli option. I got an error (I have many more but finally resolved them but stuck here):

INFO - 506 files left to upgrade.
INFO - === Step upgradeFiles
INFO - 106 files left to upgrade.
INFO - === Step upgradeFiles
INFO - All files upgraded. Now upgrading database...
INFO - Restart requested. Please run the following command to continue your upgrade:
INFO - $ modules/autoupgrade/cli-upgrade.php --dir=admin9254z9q7u --action=upgradeDb --data=eyJlcnJvciI6bnVsbCwic3RlcERvbmUiOmZhbHNlLCJuZXh0IjoidXBncmFkZUZpbGVzIiwic3RhdHVzIjoib2siLCJuZXh0X2Rlc2MiOiJJTkZPIC0gUmVzdGFydCByZXF1ZXN0ZWQuIFBsZWFzZSBydW4gdGhlIGZvbGxvd2luZyBjb21tYW5kIHRvIGNvbnRpbnVlIHlvdXIgdXBncmFkZTpcbiIsIm5leHRRdWlja0luZm8iOltdLCJuZXh0RXJyb3JzIjpbXSwibmV4dFBhcmFtcyI6eyJvcmlnaW5WZXJzaW9uIjoiMS43LjguOCIsIml [..]
INFO - === Step upgradeDb
INFO - Cleaning file cache
INFO - Running opcache_reset
PrestaShopException in /var/www/presta_us_klon/classes/db/Db.php line 303
#0 /var/www/presta_us_klon/classes/db/Db.php(236): DbCore::getClass()
#1 /var/www/presta_us_klon/config/alias.php(47): DbCore::getInstance()
#2 /var/www/presta_us_klon/classes/shop/Shop.php(1351): pSQL()
#3 /var/www/presta_us_klon/classes/shop/Shop.php(351): ShopCore::findShopByHost()
#4 /var/www/presta_us_klon/config/config.inc.php(117): ShopCore::initialize()
#5 /var/www/presta_us_klon/modules/autoupgrade/classes/UpgradeContainer.php(665): require_once('...')
#6 /var/www/presta_us_klon/modules/autoupgrade/classes/Task/AbstractTask.php(165): PrestaShopModuleAutoUpgradeUpgradeContainer->initPrestaShopCore()
#7 /var/www/presta_us_klon/modules/autoupgrade/classes/Task/Upgrade/UpgradeDb.php(90): PrestaShopModuleAutoUpgradeTaskAbstractTask->init()
#8 /var/www/presta_us_klon/modules/autoupgrade/classes/Task/Runner/ChainedTasks.php(59): PrestaShopModuleAutoUpgradeTaskUpgradeUpgradeDb->init()
#9 /var/www/presta_us_klon/modules/autoupgrade/cli-upgrade.php(50): PrestaShopModuleAutoUpgradeTaskRunnerChainedTasks->run()
#10 {main}

which is related with this class

    public static function getClass()
    {
        $class = '';
        if (PHP_VERSION_ID >= 50200 && extension_loaded('pdo_mysql')) {
            $class = 'DbPDO';
        } elseif (extension_loaded('mysqli')) {
            $class = 'DbMySQLi';
        }

        if (empty($class)) {
            throw new PrestaShopException('Cannot select any valid SQL engine.');
        }

        return $class;
    }

but as you can see I have both php7.4 extensions:

root@joffrey:/var/www# php7.4 -m | grep pdo_mysql
pdo_mysql
root@joffrey:/var/www# php7.4 -m | grep mysqli
mysqli
root@joffrey:/var/www/presta_us_klon# cat testy.php
<?php
print_r(get_loaded_extensions());
?>
root@joffrey:/var/www/presta_us_klon# php7.4 testy.php | grep -i 'mysqli|pdo_mysql'
    [33] => mysqli
    [34] => pdo_mysql

Problem using define() to enable debug mode

On Prestashop, I have a production and staging server. I want to activate debug mode on staging environment.

I can use $_SERVER['SERVER_NAME'] to identify my environment, so I can define my constant like this :

if (! defined('_PS_MODE_DEV_')) {
    define('_PS_MODE_DEV_', $_SERVER['SERVER_NAME'] === 'staging.domain.name');
}

But it’s not working, the debug mode is not enabled.

When I’m testing my values :

var_dump(! defined('_PS_MODE_DEV_')); // true
if (! defined('_PS_MODE_DEV_')) {
    var_dump($_SERVER['SERVER_NAME'] === 'staging.domain.name'); // true
    define('_PS_MODE_DEV_', $_SERVER['SERVER_NAME'] === 'staging.domain.name');
}
var_dump(_PS_MODE_DEV_); // true

Everything looks good, I don’t understand why the debug mode stills disabled.

I thought it was a problem with the mode itself, but if I set like this :

if (! defined('_PS_MODE_DEV_')) {
    define('_PS_MODE_DEV_', true);
}

It works, the debug mode is enabled…

Maybe there is some limitation with define() ? (I cannot find an example using an expression).

So, I tried like this :

if (! defined('_PS_MODE_DEV_')) {
    if ($_SERVER['SERVER_NAME'] === 'staging.domain.name') {
        define('_PS_MODE_DEV_', true);
    }
    else {
        define('_PS_MODE_DEV_', false);
    }
}

That works too, the debug mode is enabled on staging. HOWEVER, the debug mode is enabled on production too !

I am completely lost, because if I set even like this :

if (! defined('_PS_MODE_DEV_')) {
    if (false) {
        define('_PS_MODE_DEV_', true);
    }
    else {
        define('_PS_MODE_DEV_', false);
    }
}

The debug mode stills enabled… I have no idea what is going on here. For me, it looks like PHP ignores my condition, and takes always the first define().

Could someone give me some ideas to understand what happens here ?

Why a login page using password_verify doesn’t work? [duplicate]

The admin page should be accessed by entering the ‘admin’ NIC and password. The patient sites for other NICs should be accessible with their password.

Here is the patient(user) table:

id NIC Password Name Phone Address
1 admin 1234 Ben 0118675456 Colombo
2 00236584V abcd1 Ann 0114253963 Dehiwela

I used NIC as primary key in the table
here is my PHP code .

<?php
session_start();
$NIC="";
$password = "";
$error = "";
if($_SERVER['REQUEST_METHOD']=='POST')
{
    $NIC = $_POST['nic'];
    $password = $_POST['password'];
    if(empty($NIC)||empty($password))
    {
        $error = "Email and Password are required !";
    }
    else
    {
        include "database.php";
        $dbConnection = getDatabaseConnection();
        
        $statement = $dbConnection->prepare("SELECT id, NIC, Password, Name, Phone, Address FROM user WHERE NIC = ?");
        
        $statement->bind_param('s',$NIC);
        $statement->execute();
        $statement->bind_result($id, $nic, $stored_password, $Name, $Phone, $Address);
        if($statement->fetch())
        {
            if(password_verify($password,$stored_password))
            {
                if(strtolower($NIC)==="admin")
                {
                    $_SESSION["admin_id"] = $id;
                    $_SESSION["admin_username"] = $nic;                 
                    header("location: admin-dashboard.php");
                    exit;
                }
                else
                {
                    $_SESSION["id"]=$id;
                    $_SESSION["nic"]=$nic;
                    $_SESSION["Name"]=$Name;
                    $_SESSION["Password"]=$password;
                    $_SESSION["Phone"]=$Phone;
                    $_SESSION["Address"]=$Address; 
                    
                    header("location: patient-profile.php");
                    exit;
                }
            }
            else
            {
                $error="Email or Password invalid";
            }
        }
        else
        {
            $error="Email or Password invalid";
        }
        $statement->close();
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Login / Signup - Wintan Hospital</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <header>
        <img src="IMG/Logo.jpg" width="100px" height="100px" alt=""/><br>
        <h1>Wintan Hospital </h1>
    </header>

    <main>
        <section class="auth-section">
            <div class="login-form">
                <h2>Login</h2>
                <form action="patient-login.php" method="post">
                    <strong><?= htmlspecialchars($error) ?></strong>
                    <label for="username">Username/NIC:</label>
                    <input type="text" id="nic" name="nic" value="<?= htmlspecialchars($NIC) ?>">
                    <label for="password">Password:</label>
                    <input type="password" id="password" name="password">
                    <button type="submit">Login</button>
                    <a href="forgot-password.html">Forgot Password?</a>
                </form>
            </div>
        </section>
    </main>

    <footer>
        <p>&copy; 2024 Wintan Hospital. All rights reserved.</p>
    </footer>
</body>
</html>

How to Implement Pagination with API Using PHP [closed]

I’m working with the Clinical Trials API to retrieve study data using PHP. Currently, I can pull through the first 10 results as thats the default, but I’m struggling to implement pagination to access the remaining records.

I’ve tried using PHP sessions to handle the nextPageToken for pagination, but I’m having trouble utilizing the token properly. Ideally, I want to load more results incrementally (e.g 10 at a time) without fetching all the data at once, because it obviously causes my site to time out.

Here’s my code I’m currently working with


defined('ABSPATH') || exit;

// Enqueue custom CSS
function register_custom_styles() {
    wp_enqueue_style('custom-shortcode-style', get_template_directory_uri() . '/style.css', [], '1.0.0');
}
add_action('wp_enqueue_scripts', 'register_custom_styles');

// Register shortcode
add_shortcode('external_data', 'fetch_clinical_trials');

function fetch_clinical_trials($atts) {
    if (is_admin()) {
        return '<p>Shortcode [external_data] preview.</p>';
    }

    $atts = shortcode_atts(['title' => 'Clinical Trials Data'], $atts, 'external_data');

    $response = wp_remote_get('https://clinicaltrials.gov/api/v2/studies');
    if (is_wp_error($response)) {
        return 'Error fetching data.';
    }

    $studies = json_decode(wp_remote_retrieve_body($response), true)['studies'] ?? [];

    $html = '<h2>' . esc_html($atts['title']) . '</h2>';
    $html .= '<table>
                <tr><th>NCT ID</th><th>Organization</th><th>Title</th><th>Status</th><th>Start Date</th><th>Completion Date</th><th>Sponsor</th></tr>';

    foreach ($studies as $study) {
        $html .= '<tr>';
        $html .= '<td>' . esc_html($study['protocolSection']['identificationModule']['nctId'] ?? 'N/A') . '</td>';
        $html .= '<td>' . esc_html($study['protocolSection']['identificationModule']['organization']['fullName'] ?? 'N/A') . '</td>';
        $html .= '<td>' . esc_html($study['protocolSection']['identificationModule']['briefTitle'] ?? 'N/A') . '</td>';
        $html .= '<td>' . esc_html($study['protocolSection']['statusModule']['overallStatus'] ?? 'N/A') . '</td>';
        $html .= '<td>' . esc_html($study['protocolSection']['statusModule']['startDateStruct']['date'] ?? 'N/A') . '</td>';
        $html .= '<td>' . esc_html($study['protocolSection']['statusModule']['primaryCompletionDateStruct']['date'] ?? 'N/A') . '</td>';
        $html .= '<td>' . esc_html($study['protocolSection']['sponsorCollaboratorsModule']['leadSponsor']['name'] ?? 'N/A') . '</td>';
        $html .= '</tr>';
    }

    $html .= '</table>';
    return $html;
}

I understand there’s a nextPageToken for pagination, but I can’t figure out how to correctly use it to fetch subsequent results. How can I implement a proper pagination mechanism for this scenario?

Any advice or examples on how to properly handle this token for paginated requests would be greatly appreciated! Thank you !

Insert data using php to html textarea in mustache template [closed]

I read multi-line data using php from a database which has been previously validated on insertion. To create an editable form I’m using a Mustache template containing html form data with data inserted from php. SFSG with standard form elements (text, number).

However I’m not having success with trying to insert the data into a textarea with:

<div>
  <label col-sm-2" for="description">Article description:</label>
  <br>
  <textarea  name="description" rows="8" cols="45" <?php echo {{adescription}}; ?></textarea>
</div> 

Where adescription is the data item holding the text read from the database.

What I would like to achieve is that text is editable in the textarea so I can have the user edit it and then I’d check it and put it back in the database again.

WordPress Plugin development – React integration is not working

I am developing a wordpress Plugin and during development, I decided to continue the code with react, instead of Html. In order to do that I needed to build the React environment on WordPress. I have built it and it was compiling correctly. Thereby my goal was to see if react was also rendering on the wordpress page, but on the wordpress settings page of my Plugin was nothing to see from the react test component.

The expected result is that the contents of the react file renders on the settings page. For this task I got help from the WordPress Documentation. I would be very happy if any of you can help me to solve this bug.

Here is how I did the enque on the php file(the whole contents of the php file):
Look at the functions justinLegalRegisterTestPage, justinLegalRenderTestPage, justinLegalEnqueueTestPageScripts which are relevant for the react component.

<?php

/**
 * Justin Legal Plugin – Admin Settings
 *
 * This file adds the Justin Legal settings page to the admin, registers common settings
 * (including AJAX handlers), and renders the settings page with tabs by including
 * tab-specific files.
 *
 * @package JustinLegalPlugin
 */


// Prevent direct access.
if (! defined('ABSPATH')) {
    exit;
}

// Always include the tab files so that their registration functions run.
require_once plugin_dir_path(__FILE__) . 'settings/main-settings-tab.php';
require_once plugin_dir_path(__FILE__) . 'settings/compliance-tab.php';

/**
 * Add the Justin Legal settings page to the admin menu.
 */
function justinLegalAddSettingsPage()
{
    add_menu_page(
        'Justin Legal Settings',           // Page title.
        'Justin Legal',                    // Menu title.
        'manage_options',                  // Capability.
        'justin-legal-settings',           // Menu slug.
        'justinLegalRenderSettingsPage',   // Callback function.
        'dashicons-admin-generic',         // Icon.
        100                                // Position.
    );
}
add_action('admin_menu', 'justinLegalAddSettingsPage');


/**
 * Render the settings page with tabs.
 * The URL remains unchanged (no query parameters are appended) because the tab switching
 * is handled via JavaScript.
 */
function justinLegalRenderSettingsPage()
{
?>
    <div class="wrap">
        <h1>Justin Legal Settings</h1>
        <h2 class="nav-tab-wrapper">
            <a href="#" class="nav-tab nav-tab-active" data-tab="main">Main Settings</a>
            <a href="#" class="nav-tab" data-tab="compliance">Compliance</a>
        </h2>

        <div id="tab-main">
            <?php justinLegalRenderMainSettingsTab(); ?>
        </div>
        <div id="tab-compliance" style="display: none;">
            <?php justinLegalRenderCompliance(); ?>
        </div>
    </div>
<?php
}

/**
 * AJAX handler to retrieve profile data from the external API.
 */
function justinLegalGetProfileData()
{
    if (! current_user_can('manage_options')) {
        wp_send_json_error('Permission denied');
    }

    $options = get_option('justin_legal_settings');
    $encodedId = '';
    if (isset($_POST['lawfirm']) && ! empty($_POST['lawfirm'])) {
        $encodedId = sanitize_text_field($_POST['lawfirm']);
    } else {
        $encodedId = isset($options['lawfirm']) && ! empty($options['lawfirm']) ? $options['lawfirm'] : 'sFuCvloJ';
    }

    $apiUrl = 'https://justin-api-dev.azurewebsites.net/api/v1/LawFirm/encoded/' . urlencode($encodedId);
    $response = wp_remote_get($apiUrl);
    if (is_wp_error($response)) {
        wp_send_json_error($response->get_error_message());
    }
    $code = wp_remote_retrieve_response_code($response);
    $body = wp_remote_retrieve_body($response);
    if ($code != 200) {
        wp_send_json_error('API returned HTTP code ' . $code . ': ' . $body);
    }
    $data = json_decode($body, true);
    if (empty($data) || ! is_array($data)) {
        wp_send_json_error('Empty data returned from API');
    }
    $kanzleiName = isset($data['name']) ? sanitize_text_field($data['name']) : '';
    $options['kanzlei_name_customer'] = $kanzleiName;

    update_option('justin_legal_settings', $options);
    wp_send_json_success(array('kanzlei_name' => $kanzleiName));
}
add_action('wp_ajax_justin_legal_get_profile_data', 'justinLegalGetProfileData');

/**
 * Enqueue admin scripts on the Justin Legal settings page.
 */
function justinLegalAdminScripts($hook)
{
    if ($hook !== 'toplevel_page_justin-legal-settings') {
        return;
    }
    wp_enqueue_script(
        'justin-legal-admin-js',
        plugin_dir_url(__FILE__) . 'js/admin.js',
        array('jquery'),
        filemtime(plugin_dir_path(__FILE__) . 'js/admin.js'),
        true
    );
}
add_action('admin_enqueue_scripts', 'justinLegalAdminScripts');


/**
 * Enqueue the Justin Legal widget CSS in WP Admin
 */
function justinLegalEnqueueWidgetCSS($hook)
{
    if ($hook === 'toplevel_page_justin-legal-settings') {
        wp_enqueue_style(
            'justin-legal-widget-css',
            'https://widgets.justin-legal.com/index.css',
            array(), // without array() it will not work
            null
        );
    }

    wp_enqueue_style(
        'justin-legal-admin-overrides',
        plugin_dir_url(__FILE__) . 'css/admin.css',
        array('justin-legal-widget-css'),
        filemtime(plugin_dir_path(__FILE__) . 'css/admin.css')
    );
}
add_action('admin_enqueue_scripts', 'justinLegalEnqueueWidgetCSS');


// Register the Test Page as a Subpage under the Justin Legal settings page.
function justinLegalRegisterTestPage()
{
    add_submenu_page(
        'justin-legal-settings',             // Correct parent slug (matches your add_menu_page slug)
        __('Test Page', 'justin-legal'),     // Page title
        __('Test Page', 'justin-legal'),     // Menu title
        'manage_options',                    // Capability required
        'test-page',                         // Menu slug
        'justinLegalRenderTestPage'          // Callback to render the page
    );
}
add_action('admin_menu', 'justinLegalRegisterTestPage');

function justinLegalRenderTestPage()
{
    printf(
        '<div class="wrap" id="justin-legal-test-page">%s</div>',
        esc_html__('Loading…', 'justin-legal')
    );
}


function justinLegalEnqueueTestPageScripts($hook)
{
    if ($hook !== 'justin-legal-settings_page_test-page') {
        return;
    }

    $asset_file = plugin_dir_path(__FILE__) . 'build/index.asset.php';
    if (! file_exists($asset_file)) {
        wp_die('The asset file for the Test Page does not exist. Run `npm run build` to create it.');
    }
    $asset = include $asset_file;

    wp_enqueue_script(
        'justin-legal-admin-script',
        plugin_dir_url(__FILE__) . 'build/index.js',
        $asset['dependencies'],
        $asset['version'],
        array(
            'in_footer' => true,
        )
    );

    wp_localize_script(
        'justin-legal-admin-script',
        'justinLegalData',
        array(
            'nonce' => wp_create_nonce('justin_legal_nonce'),
            'ajaxUrl' => admin_url('admin-ajax.php')
        )
    );
}
add_action('admin_enqueue_scripts', 'justinLegalEnqueueTestPageScripts');

And here is the src/index.jsx:

import domReady from "@wordpress/dom-ready";
import { createRoot } from "@wordpress/element";

const SettingsPage = () => {
  return <div>Placeholder for settings page</div>;
};

domReady(() => {
  const container = document.getElementById("justin-legal-test-page");

  if (container) {
    const root = createRoot(container);
    root.render(<SettingsPage />);
  } else {
    console.error("Container #justin-legal-test-page not found");
  }
});

On the browser page, I don’t see any error. When I run npm run build:

asset index.js 587 bytes [emitted] [minimized] (name: index)
asset index.asset.php 133 bytes [emitted] (name: index)
Entrypoint index 720 bytes = index.js 587 bytes index.asset.php 133 bytes
orphan modules 126 bytes [orphan] 3 modules
runtime modules 663 bytes 3 modules
./src/index.js + 3 modules 674 bytes [not cacheable] [built] [code generated]
webpack 5.98.0 compiled successfully in 1398 ms

And when I run npm run start:

> package.json@1.0.0 start
> wp-scripts start

asset index.js 5.26 KiB [emitted] (name: index) 1 related asset
asset index.asset.php 133 bytes [emitted] (name: index)
Entrypoint index 5.39 KiB (3.75 KiB) = index.js 5.26 KiB index.asset.php 133 bytes 1 auxiliary asset
runtime modules 937 bytes 4 modules
built modules 674 bytes [built]
  ./src/index.js 548 bytes [built] [code generated]
  external ["wp","domReady"] 42 bytes [built] [code generated]
  external ["wp","element"] 42 bytes [built] [code generated]
  external "ReactJSXRuntime" 42 bytes [built] [code generated]
webpack 5.98.0 compiled successfully in 343 ms
asset index.js 5.26 KiB [emitted] (name: index) 1 related asset
asset index.asset.php 133 bytes [emitted] (name: index)
Entrypoint index 5.39 KiB (3.75 KiB) = index.js 5.26 KiB index.asset.php 133 bytes 1 auxiliary asset
runtime modules 937 bytes 4 modules
cached modules 126 bytes [cached] 3 modules
./src/index.js 548 bytes [built] [code generated]

Nextcloud error not logged in the server log [closed]

I’m migrating a Nextcloud server to another Rocky Linux server. At first I got this error in the browser:

Internal Server Error

The server encountered an internal error and was unable to complete your request.
Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.
More details can be found in the server log.

And found it in the data/nextcloud.log:

Failed to connect to the database: An exception occurred in the driver: could not find driver

Then I installed the missing driver but still I have an error but now there is nothing in the server log.

Already searched in /var/log/httpd and /var/log/php-fpm/

How to debug?

I solved the problem by installing missing php modules. But still the question about the log persists.