When I try to run my Codeigniter application with ‘php spark serve’ this message appears “Could not open input file: spark”

I was tasked to maintain an application developped with Codeigniter 3 and php 5, noting that I’ve never worked with Codeigniter before.

When I tried to run the server from the command prompt locally using the line php spark serve , here’s what I get :

Could not open input file: spark

Btw, I use Xampp and php 8

These are all the folders of the application :

tree folders image of the website without spark file

As you can see, there is no file called “spark” which may be the reason why the server doesn’t run as it is suppose to. However, I was told that the website ran well when it was online.

I still haven’t modified any thing in the code because I don’t want to mess anything knowing that the application was fully functionnal when it was online.

what should I do to run it on my pc ?

how to deploy laravel (using mysql) to railway.app

  • deploy laravel in railway.app ( using database mysql ) errors

  • I use github repository https://github.com/TanhGL/tanhpn_blog-railway.app

  • Variable configuration

    APP_NAME=Laravel
    APP_ENV=production
    APP_KEY=base64:cXdsNTZkbWduMjNyOHhiZmJyNzltc2JtaXUwejFud3Q=
    APP_DEBUG=true APP_URL=http://localhost
    DB_CONNECTION=mysql
    DB_HOST=containers-us-west-129.railway.app
    DB_PORT=6776 DB_DATABASE=railway
    DB_USERNAME=root
    DB_PASSWORD=t92HyZDL0Ewhi0th9kMg
    NIXPACKS_BUILD_CMD=composer install && php artisan key:generate && php artisan migrate && php artisan db:seed  && php artisan storage:link && php artisan passport:keys && php artisan optimize && php artisan config:clear && php artisan cache:clear && php artisan migrate --force && npm install bower && ./node_modules/bower/bin/bower install && npm run prod
    
  • I tried many ways but all railway.app error errors image on here

Laravel sail 10, getting 503 Service Unavailable by running sail up -d

Sinds today if I run sail artisan up -d I get 503 Service Unavailable.
My Docker on my pc is up to date. I have run different commands in the hope that it wil solve the problem but it didn’t.

This is my docker-compose.yml

version: '3'
services:
    laravel.test:
        build:
            context: ./vendor/laravel/sail/runtimes/8.1
            dockerfile: Dockerfile
            args:
                WWWGROUP: '${WWWGROUP}'
        image: sail-8.1/app
        extra_hosts:
            - 'host.docker.internal:host-gateway'
        ports:
            - '${APP_PORT:-80}:80'
        environment:
            WWWUSER: '${WWWUSER}'
            LARAVEL_SAIL: 1
            XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
            XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
        volumes:
            - '.:/var/www/html'
        networks:
            - sail
        depends_on:
            - mysql
            - redis
            - meilisearch
            - selenium
    mysql:
        image: 'mysql/mysql-server:8.0'
        ports:
            - '${FORWARD_DB_PORT:-3306}:3306'
        environment:
            MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
            MYSQL_ROOT_HOST: "%"
            MYSQL_DATABASE: '${DB_DATABASE}'
            MYSQL_USER: '${DB_USERNAME}'
            MYSQL_PASSWORD: '${DB_PASSWORD}'
            MYSQL_ALLOW_EMPTY_PASSWORD: 1
        volumes:
            - 'sailmysql:/var/lib/mysql'
        networks:
            - sail
        healthcheck:
            test: [ "CMD", "mysqladmin", "ping", "-p${DB_PASSWORD}" ]
            retries: 3
            timeout: 5s
    redis:
        image: 'redis:alpine'
        ports:
            - '${FORWARD_REDIS_PORT:-6379}:6379'
        volumes:
            - 'sailredis:/data'
        networks:
            - sail
        healthcheck:
            test: [ "CMD", "redis-cli", "ping" ]
            retries: 3
            timeout: 5s
    meilisearch:
        image: 'getmeili/meilisearch:latest'
        platform: linux/x86_64
        ports:
            - '${FORWARD_MEILISEARCH_PORT:-7700}:7700'
        volumes:
            - 'sailmeilisearch:/data.ms'
        networks:
            - sail
        healthcheck:
            test: [ "CMD", "wget", "--no-verbose", "--spider",  "http://localhost:7700/health" ]
            retries: 3
            timeout: 5s
    mailhog:
        image: 'mailhog/mailhog:latest'
        ports:
            - '${FORWARD_MAILHOG_PORT:-1025}:1025'
            - '${FORWARD_MAILHOG_DASHBOARD_PORT:-8025}:8025'
        networks:
            - sail
    selenium:
        image: 'selenium/standalone-chrome'
        volumes:
            - '/dev/shm:/dev/shm'
        networks:
            - sail
networks:
    sail:
        driver: bridge
volumes:
    sailmysql:
        driver: local
    sailredis:
        driver: local
    sailmeilisearch:
        driver: local

I have searched to find a soloution but I haven’t found it yet. I’m wondering how it is possible that sudenly it doesn’t work any more.
I hope you can help me..
Thx

Binance order error Invalid API-key, IP, or permissions for action

“code” => -2015
“msg” => “Invalid API-key, IP, or permissions for action.”

I get this error when I try to place a **STOP LOSS ** order on the binance api.

I have done the following;

  1. Whitelist my IP address in the api management
  2. Tried placing the order manually on binance and it was opened.
  3. Checked the trading permission on the api management

Below is my code snippet

function getPricision($symbol)
{
    // Make a request to get the symbol details
    $symbol_info = json_decode(file_get_contents('https://api.binance.com/api/v3/exchangeInfo?symbol=' . $symbol), true);
    if (isset($symbol_info['symbols']) && !empty($symbol_info['symbols'])) {
        // Get the first symbol in the list (assuming there's only one matching symbol)
        $symbol_data = $symbol_info['symbols'][0];

        // Find the lot size filter
        $lot_size_filter = array_filter($symbol_data['filters'], function ($filter) {
            return $filter['filterType'] === 'LOT_SIZE';
        });

        // Check if the lot size filter is found
        if (!empty($lot_size_filter)) {
            $lot_size = floatval($lot_size_filter[1]['stepSize']);
            $precision = intval(round(-log10($lot_size), 0));

            return $precision;
        }
    }

    return false;
}


    // Set the required parameters for the limit trade
    $api_key = env('BINANCE_API_KEY');
    $api_secret = env('BINANCE_SECRET_KEY');
    $api_endpoint = 'https://api.binance.com';
    $symbol = 'ALGOUSDT';
    $side = 'BUY';
    
    $entryPrice = 0.1487;
    
    $side = 'BUY';
    $order_type = 'STOP_LOSS';
    $stop_price = $entryPrice; 
    $limit_price = $entryPrice; 
    $amount = 20; // Set the amount 
    
    
    // Calculate the quantity based on the desired amount
    $quantity = $amount / $limit_price;
    
    // Format the quantity, stop price, and limit price to the correct precision
    $formatted_quantity = number_format($quantity, getPricision($symbol), '.', '');
    
    // Create the order payload
    $timestamp = time() * 1000;
    $params = [
        'symbol' => $symbol,
        'side' => $side,
        'type' => $order_type,
        'quantity' => $formatted_quantity,
        'stopPrice' => $stop_price,
        'price' => $limit_price,
        'timeInForce' => 'GTC', // Good 'Til Canceled
        'timestamp' => $timestamp,
    ];
    
    //dd($params);
    // Generate the query string and sign it
    $query_string = http_build_query($params);
    $signature = hash_hmac('sha256', $query_string, $api_secret);
    $params['signature'] = $signature;
    
    // Send the signed request to place the order
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $api_endpoint . '/api/v3/order');
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string . '&signature=' . $signature);
    curl_setopt($ch, CURLOPT_HTTPHEADER, ['X-MBX-APIKEY: ' . $api_key]);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    
    // Process the response
    $response_data = json_decode($response, true);
    if (isset($response_data['orderId'])) {
        echo 'Order placed successfully! Order ID: ' . $response_data['orderId'];
    } else {
        echo 'Failed to place the order. Error: ' . $response;
    }
    
    // Close the cURL request
    curl_close($ch);
    
    dd($response_data);

Please what is wrong here, I have been pulling my hair with no luck

I want to access to user id in functions.php in custom hook

I’m using “store file uploads for contact form 7” plugin. this plugin returned attachment id by following hook:

function example_callback_id_generated($attachment_id)
{
return attachment_id;
}

add_action('nmr_create_attachment_id_generated', 'example_callback_id_generated', 10, 1);

I want to get current user id in this function to attach file upload to the user by following code:

function example_callback_id_generated($attachment_id)
{
update_user_meta(get_current_user_id(), 'ownership_document', $attachment_id);
}

add_action('nmr_create_attachment_id_generated', 'example_callback_id_generated', 10, 1);

but current user id always is 0

I used get_current_user_id(); in functions.php but I always get 0;

Please help to solve this problem.

PHP PDO Update working but Insert does not, error reporting on, no errors

For some reason the following code works when the object needs to be updated, but not when it needs to be created. I have set all error-related configurations on:

 $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 error_reporting(E_ALL);
 ini_set('display_errors', 0);
 ini_set('log_errors', 1);

Yet I just get no errors at all. Everthing seems fine, I don’t think the code itself has errors. Note the commented lastInsertId(). When using this line, it works (it inserts the data, but there is no response to return as it should be:

foreach ($ArraySecundaria as $subcontacto) {
$stmt = $conn->prepare(
    "SELECT COUNT(*) FROM subagenda WHERE id_contacto = ?"
);
$stmt->execute([$subcontacto["id_contacto"]]);
$count = $stmt->fetchColumn();

if ($count > 0) {
    $stmt = $conn->prepare("UPDATE subagenda SET
    nombre_contacto = ?,
    cargo_contacto = ?,
    telefonos_contacto = ?,
    emails_contacto = ?,
    comentario_contacto = ?
    WHERE id_empresa = ? AND id_contacto = ?");

    $update_subagenda_values = [
        maybe_null($subcontacto["nombre_contacto"]),
        maybe_null($subcontacto["cargo_contacto"]),
        maybe_null($subcontacto["telefonos_contacto"]),
        maybe_null($subcontacto["emails_contacto"]),
        maybe_null($subcontacto["comentario_contacto"]),
        $subcontacto["id_empresa"],
        $subcontacto["id_contacto"],
    ];

    if (!$stmt->execute($update_subagenda_values)) {
        $errores[] = $subcontacto["id_contacto"];
    }
} else {
    // id does not exist, create it.

    $stmt = $conn->prepare("INSERT INTO subagenda (
        id_empresa,nombre_contacto,cargo_contacto,telefonos_contacto, 
        emails_contacto,comentario_contacto) VALUES (?,?,?,?,?,?)");
    $insert_subagenda_values = [
        $subcontacto["id_empresa"],
        $subcontacto["nombre_contacto"],
        maybe_null($subcontacto["cargo_contacto"]),
        maybe_null($subcontacto["telefonos_contacto"]),
        maybe_null($subcontacto["emails_contacto"]),
        maybe_null($subcontacto["comentario_contacto"]),
    ];

    
    $res = $stmt->execute($insert_subagenda_values);
    /* $stmt->lastInsertId(); when using this line, it works, but there is nothing to responde to return as it should be  */ 
    if (!$res) {
        $errores[] = $subcontacto["id_empresa"];
    } 
  }
}
if (!empty($errores)) {
    $response["success"] = false;
    $response["message"] = "Error al actualizar los datos.";
} else {
    $response["success"] = true;
    $response["message"] = "Datos guardados correctamente.";
}
echo json_encode($response);

For clarification, maybe_null is a simple function that finds if the variable could be null or “null” as string.

function maybe_null($string){
    if (is_null($string) || $string === "null" || $string === "NULL" || !isset($string)) {
        return "";
    } else {
        return $string;
    }
}

Save data from join query to nested model in Laravel Eloquent

I had troubles when I use join queries like this:
`

$contract->actions()->orderBy('action_types.name, 'DESC')
            ->join('action_types', 'action_types.id', '=' , 'actions.type_id')
            ->paginate($data->perPage, page: $data->page);

Join neccessary for ordering by nested table. So after this query executing, I have to take names data from model ActionTypes. So, I already have this data by join query, but this data saved in model Action. And when i try call Action->actionType->name query executing again. I want to avoid this and save data from join to nested model. How i can do this? Thanks for any help.

I tried save data from parent table but this may take many time;
I tried use with method but this dont ordering my data correctly.

Search data to update or delete it not working [closed]

I have a search bar in a page that shows a table. When I update or delete the data from the main page with the action buttons it works but when I search for a particular row and try the same it does not work although the data is being fetched when I click the update action button but when I cick update in the modal that appears, it does not work. The update and delete modal are both in different php files and the buttons target them. The search bar also uses AJAX and the display is in another php file whose results are displayed in the main page

I inspected the page to see if there was an error but nothing is showing there.

Yii2 creating a get method for a mysql table column doesn’t work

I’m creating a class that gets values from my database.
My database looks like this:

  id  |  value  |  quantity  |  type  |
---------------------------------------
  1   |  134    |  12        |  1     |
---------------------------------------
  2   |  21     |  2         |  1     |
---------------------------------------
  3   |  211    |  53        |  1     |

Right now my class looks like this:

?php

namespace commonclasses;

use commonmodelsdbstockType;
use yiidbActiveRecord;

class Stock extends ActiveRecord
{
    /**
     * @var stockType
     */
    public $StockData;

    public function run()
    {
        $this->StockData::find()
            ->select([
                'SUM(quantity) as stockQuantity',
                'SUM(value) as stockValue'
            ])
            ->where(['type' => 1])
            ->asArray()
            ->one();
    }


    public function getQuantity()
    {
        return $this->StockData::findOne(['column' => 'stockQuantity']);
    }

And in my view I do this:

<?php

use commonclassesStock;

$stock = new Stock()

?>

<div class='row'>
      <?= $stock->getQuantity() ?>
</div>

I would love to see the quantity in my view but I keep getting the following error:
Class name must be a valid object or a string

It points to the get method return, but I have no idea how to fix it.

Fatal error: Uncaught TypeError when accessing offset of type string in Houzez theme’s index.php” [closed]

“Hello forum members,

I’m encountering a fatal error in the Houzez WordPress theme’s index.php file and I’m seeking assistance in resolving it. The error message I’m receiving is as follows:

‘Fatal error: Uncaught TypeError: Cannot access offset of type string on string in C:xampp3htdocswordpresswp-contentthemeshouzezindex.php:6 Stack trace: #0’

The error seems to be related to accessing an offset of a string variable on line 6 of the index.php file. Here is the line of code causing the issue:

‘if( $sticky_sidebar[‘default_sidebar’] != 0 ) {‘

I haven’t made any modifications to the theme or the index.php file. Can someone please help me understand what could be causing this error and suggest possible solutions? I’d appreciate any insights or guidance.

Thank you in advance for your assistance!”

How to keep the indentation after submitting a text input form

I’m having a little problem : when I save the text input into my database with indentation it gets saved correctly, for example, If I type in :

  1. first
  2. second
  3. third

After submitting this text input, it’s gonna be saved in my database exactly the way I wrote it, however, when I try to get the saved input and display it on the page, I receive it without any indentation just like so : 1. first 2. second 3. third.
How can I keep the correct indentation when getting the data from the database? Appreciate any tips!

Unable to load dynamic library, PHP Homebrew MacOS

I am running MacOs M1 Chip and I have php8.2 installed via homebrew. I need maatwebsite/excel package for my project. Whenever I try to composer install/update it always says

enter image description here

and the composer install/update failed.

I have tried to enable the extensions in php.ini by removing the “;”, but the result is still the same.

How do I order multidimensional array by average order of sub-arrays PHP

Sorry for the confusing sounding title

I have some rows from a database that I have performed array_flip() on, and I have also ordered each sub-array by values using some complicated sorting patterns

I now have data in the form:

array(
   'col1' => (0=>'value',1=>'value',2=>'value',3=>'value')
   'col2' => (1=>'value',2=>'value',0=>'value',3=>'value')
   'col3' => (0=>'value',2=>'value',1=>'value',3=>'value')

Note that the 0,1,2,3 are not in order for each sub-array

What I want is to come up with an order that is the average across all columns, in the case of these 3 it would be: 0, 2, 1, 3

I then want to apply this order to all columns, so they are all in the order 0, 2, 1, 3

I can then flip the columns back again, and re-insert into a new table, then happy days all my items are in order

It is probably an easy problem, but I am just not seeing the solution, could anybody please point me in the right direction?

Note: Column count and column names varies

QuickChart Chart.js unexpected identifier

I want to send a dynamically generated image, created with quickChart, with email in php. For testing i created the chartConfig in the quickChart Sandbox, everything is fine. When i copypaste the config to my php an start it, then i get ChartError: Error: unexpected identifier – 18:26. I don’t get it what the problem is. Here is my code:

$chartConfig = '{
  type: "horizontalBar",
  data: {
    labels: ["Sei perfekt", "Streng dich an", "Sei schnell", "Sei gefaellig", "Sei stark"],
    datasets: [
      {
        backgroundColor: ["#97cc64", "#97cc64", "#97cc64", "#97cc64", "#97cc64"],
        data: [26, 30, 25, 26, 25],
        barThickness: 30,
      },
      {
        backgroundColor: ["#ffd050", "#ffd050", "#ffd050", "#ffd050", "#ffd050"],
        data: [null, 10, null, null, null],
        barThickness: 30,
      },
      {
        backgroundColor: ["#fd5a3e", "#fd5a3e", "#fd5a3e", "#fd5a3e", "#fd5a3e"],
        data: [null, 5, null, null, null],
        barThickness: 30,
      },
    ],
  },
  options: {
    legend: {
      position: "bottom",
      labels: {
        generateLabels: (chart) => [
          {
            text: "Gesund",
            fillStyle: "#97cc64",
          },
          {
            text: "Uebermaessig",
            fillStyle: "#ffd050",
          },
          {
            text: "Negativ",
            fillStyle: "#fd5a3e",
          },
        ],
      },
    },
    scales: {
      xAxes: [
        {
          stacked: true,
          ticks: { min: 0, max: 50, display: true },
          gridLines: { display: true },
        },
      ],
      yAxes: [{ stacked: true, gridLines: { drawBorder: false } }],
    },
  },
}';
 
$chartUrl = 'https://quickchart.io/chart?w=500&h=300&c=' . Urlencode($chartConfig);

$chartUrl is then added to my html. But instead the chart, i get the error image in the email.

Thank you!