Ninja forms submissions not loading

I am using Ninja forms on a website. I gave one user the access to view the submissions. He can see the menu item. But when trying to load the submissions from a form. All he sees is a spinning wheel and the console shows:

Error:{ "code": "rest_forbidden", "message": "You have no permission to do this", "data": {"status": 403}}

I used the following code in the functions.php to manage the capabilities (and the plugin user role editor):

add_filter( 'ninja_forms_admin_parent_menu_capabilities',   'nf_subs_capabilities' ); 
add_filter( 'ninja_forms_admin_all_forms_capabilities',     'nf_subs_capabilities' ); 
add_filter( 'ninja_forms_admin_submissions_capabilities',   'nf_subs_capabilities' ); 

function nf_subs_capabilities( $cap ) {
    return 'nf_submissions'; // EDIT: User Capability
}

What did I miss?

Laravel : Fortify : Illegal Offset Type

I’m about to add 2FA using Google Authenticator to my application but I have issues with adding Fortify.

My laravel project is years old, but I’m updating it to the newest versions. Right now I’m using laravel 11 (upgraded recently from 9).

Issue that I’m facing is somehow connected to middleware. I figured out that this code is causing troubles:

 $twoFactorMiddleware = Features::optionEnabled(Features::twoFactorAuthentication(), 'confirmPassword')
        ? [config('fortify.auth_middleware', 'auth').':'.config('fortify.guard'), 'password.confirm']
        : [config('fortify.auth_middleware', 'auth').':'.config('fortify.guard')];

That is actually from Fortify routes.

So when I try to enable 2FA for user using their route:

Route::post(RoutePath::for('two-factor.enable', '/user/two-factor-authentication'), [TwoFactorAuthenticationController::class, 'store'])
        ->middleware($twoFactorMiddleware)
        ->name('two-factor.enable');

It is giving me an error “Illegal offset type” in file ‘vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php’. After removing ->middleware($twoFactorMiddleware) I don’t receive error anymore and 2FA secret is set properly.

AuthManger.php:

public function guard($name = null)
{
    $name = $name ?: $this->getDefaultDriver();

    return $this->guards[$name] ?? $this->guards[$name] = $this->resolve($name);
}

I tried reinstalling fortify and reinstalling everything from composer but it didn’t help. ALthough I did setup new laravel 11 project and everything worked just fine. I’ve lost hours on this issue and still nothing. Any help is much appreciated, thanks !

Mix clips and audio using Google Transcoder

Im newbie using Google Transcoder API. I need it to join some clips (with their own audio) and one audio more like background music. Im using php.

I have tried several things and read a lot of posts, but none was useful about I need. I tried to add the audio-only as new Input. Also I tried to join the clips and audio in the Atom, but this resets the audio in every clip. I would like a continuous music.

ElasticSearch – ElasticElasticsearchExceptionClientResponseException

Ive implemented ElasticSearch in our organization application and all went well so far, but when I tried to add conditions to the query it started throw 400s on almost everything I try following their documentation.

My struggle is to query for only products with status ‘active’.

Here is a code snippet.

       $products = $this->elasticsearch->search([
            'index' => $product->getSearchIndex(),
            'type' => $product->getSearchType(),
            'body' => [
                '_source' => ['category_id', 'title', 'status'],
                'size' => 30,
                'query' => [
                    'bool' => [
                        'must' => [
                            'multi_match' => [ // ^1 means that title field has a higher priority in search tree
                                'fields' => ['title^1'],
                                'type' => 'phrase_prefix',
                                'query' => $query,
                            ],
                            'bool' => [
                                'must' => [
                                    [
                                        'term' => ['status' => ProductStatus::ACTIVE]
                                    ],
                                ],
                            ],
                        ],
                    ],
                ],
            ],
        ]);

Here is the full exception text I get from elastic using this piece of code above.

400 Bad Request: {"error":{"root_cause":[{"type":"parsing_exception","reason":"[multi_match] malformed query, expected [END_OBJECT] but found [FIELD_NAME]","line":1,"col":170}],"type":"x_content_parse_exception","reason":"[1:170] [bool] failed to parse field [must]","caused_by":{"type":"parsing_exception","reason":"[multi_match] malformed query, expected [END_OBJECT] but found [FIELD_NAME]","line":1,"col":170}},"status":400}

I tried using filters and so forth, but none of the instructions in docs kind of lead me to success.

What am I missing?

How to get PHP 8 with parallel extension working on Linux?

I’m trying to install PHP 8 with the extension parallel, with the only purpose of running an implementation in PHP for the One Billion Rows Challenge. I’m using Ubuntu 22.04 on WSL2 with Windows 11 as host.

However, I’ve followed this, this and this, but none of them worked. The last one was using PHP 7, so I adjusted everything, including the change of --enable-maintainer-zts to --enable-zts in the ./configure command.

Here is the exact script I used for the last one. Everything worked well, 0 exit code.

However, when I run the following (note the script links the new PHP to /usr/bin/phpz), as the README.md instructs,

phpz -d extension=parallel calculateAverage.php 4

I get this error:

Fatal error: Uncaught Error: Class "parallelRuntime" not found in /home/helitonmrf/projects/1brc/php_realFlowControl/calculateAverage.php:102
Stack trace:
#0 {main}
  thrown in /home/helitonmrf/projects/1brc/php_realFlowControl/calculateAverage.php on line 102

I’ve also installed ext-parallel, but I still get this:

PHP Warning:  PHP Startup: Unable to load dynamic library 'parallel' (tried: /etc/php8z/lib/php/extensions/no-debug-zts-20230831/parallel (/etc/php8z/lib/php/extensions/no-debug-zts-20230831/parallel: cannot open shared object file: No such file or directory), /etc/php8z/lib/php/extensions/no-debug-zts-20230831/parallel.so (/etc/php8z/lib/php/extensions/no-debug-zts-20230831/parallel.so: cannot open shared object file: No such file or directory)) in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library 'parallel' (tried: /etc/php8z/lib/php/extensions/no-debug-zts-20230831/parallel (/etc/php8z/lib/php/extensions/no-debug-zts-20230831/parallel: cannot open shared object file: No such file or directory), /etc/php8z/lib/php/extensions/no-debug-zts-20230831/parallel.so (/etc/php8z/lib/php/extensions/no-debug-zts-20230831/parallel.so: cannot open shared object file: No such file or directory)) in Unknown on line 0

What can I do?

Old PHP Code not working in Newer Versions [duplicate]

I wrote code some time ago which worked using an earlier version of PHP and MySQL.

When I try to do a search for a specific product, it is supposed to display all products containing the key word – let’s say “Monitors”.

Unfortunately I was getting errors. I have found some solutions but as for this “Search” issue, I cannot find a solution. One suggestion was to go from mysql, to mysqli in the code. Still that error persists. I get a very similar error in Login, and Create an account.

The error reads:

Fatal error: Uncaught ArgumentCountError: mysqli_query() expects at
least 2 arguments, 1 given in
C:xampphtdocsComputerSuperStoresearch.php:39 Stack trace: #0
C:xampphtdocsComputerSuperStoresearch.php(39):
mysqli_query(‘select * from p…’) #1 {main} thrown in
C:xampphtdocsComputerSuperStoresearch.php on line 39

The Code Reads:

<?php // Queries All Items using Brand or Looking for specific items 
  $query = "select * from products where Brand like "%$trimmed%" OR Item like "%$trimmed%" OR ItemType like "%$trimmed%" OR Category like "%$trimmed%" order by Brand";

    **Line 39** $numresults=mysqli_query($query); **Line 39**
    $numrows=mysqli_num_rows($numresults);

    if($numrows==0)
    {
      echo"<h2>Results</h2>";
      echo"<p><h3>Sorry, your search for</h3><h2> &quot; ". $trimmed . " &quot; </h2><h3>Returned zero results...</h3></p>";
    }

    if(empty($s))
    {
        $s=0;
    }

    $query .= " limit $s,$limit";
    $result = mysqli_query($query) or die("Couldn't execute query");
    //echo"Results";
    $count = 1 + $s;
    
    while ($row=mysqli_fetch_assoc($result)) {
        include ('tablelogincheck.php');
    }
?>

I have highlighted the line where it says there is an error using ** Line 39**.

Previously i used mysql_ and as I said, it all worked fine in the older version.

I changed it to mysqli_ but it has not fixed the errors in Search, Login, Create Account.

The latter 2 give very similar errors – just a different line number.

I have spent a fair time trying to figure it out (years) and to no avail. Any help would be appreciated.

PHP how to recreate the random order of an array after chunk

For an online game I create an initial PHP array with 36 values: A-Z 0-9. A random script remix the array, i.e

[0] R
[1] 4
[2] N
[3] d
...
[35] 8

Once done the script assigns 6 signs to each of the 6 players via a chunk($arr,6).

Player 1 [0] = [R,4,n,d,O,M]
Player 2 [1] = [p,2,s,Z,k,u]
...
Player 6 [5] = [J,r,V,5,z,8]

The question is: once the table of players has been reordered alphabetically, is there an algorithmic way to recreate the initial distribution?

To simplify the question:

Initial array

[0] = abc
[1] = def
[2] = ghi
[3] = jkl
[4] = mno
[5] = pqr

Random order permutation [0,1,2,3,4,5] -> [2,5,0,3,1,4]:

[2] = ghi
[5] = pqr
[0] = abc
[3] = jkl
[1] = def
[4] = mno

Result:

new order     [0]   [1]   [2]   [3]   [4]   [5] 
value         ghi   pqr   abc   jkl   def   mno
former order  [2]   [5]   [0]   [3]   [1]   [4] -> random permutation

To retrieve former order I must find the way to produce the array [2,4,0,3,5,1]:

 new order   [2]   [4]   [0]   [3]   [5]   [1]          
 value       abc   def   ghi   jkl   mno   pqr  -> initial array order

How to obtain this array [2,4,0,3,5,1] from random permutation [2,5,0,3,1,4] ?

Issue adding heart Icon to Bootstrap 5 Carousel

The heart/favorities icon in bootstrap 5 carousel is not working. How to add proper functionality to it so that it appears filled (red colored) when clicked and appears empty (white colored) when clicked again.

<div id="myCarousel" class="carousel slide" data-bs-ride="carousel">
     <!-- Heart Icon -->
     <div class="heart-icon">
        <i class="bi bi-heart"></i>
    </div>
    <div class="carousel-indicators ml-0 mr-4 w-25">
        <button type="button" data-bs-target="#myCarousel" data-bs-slide-to="0" class="active" aria-current="true" aria-label="Slide 1"></button>
        <button type="button" data-bs-target="#myCarousel" data-bs-slide-to="1" aria-label="Slide 2"></button>
        <button type="button" data-bs-target="#myCarousel" data-bs-slide-to="2" aria-label="Slide 3"></button>
        <button type="button" data-bs-target="#myCarousel" data-bs-slide-to="1" aria-label="Slide 4"></button>
        <button type="button" data-bs-target="#myCarousel" data-bs-slide-to="2" aria-label="Slide 5"></button>
      </div>
    <div class="carousel-inner w-50 rounded-4">
       <!--  Video Slide -->
       <div class="carousel-item active">
          <video class="d-block w-100 rounded-4" controls>
            <source src="{{ asset('venues/venue1/vid1.mp4')}}" type="video/mp4">
            Your browser does not support the video tag.
          </video>
          {{-- <div class="carousel-caption d-none d-md-block">
            <h5>Soccer Pro</h5>
            <p>The best stadium at affordable rates</p>
          </div> --}}
        </div>
      <!-- Image Slide 1 -->
      <div class="carousel-item">
        <img src="{{ asset('venues/venue1/1.png')}}" class="d-block w-100 rounded-4" alt="Image Slide">
        {{-- <div class="carousel-caption d-none d-md-block">
          <h5>Soccer Pro</h5>
          <p>Etihad vs DXB Strikers</p>
        </div> --}}
      </div>
     <!-- Image Slide 2 -->
     <div class="carousel-item">
      <img src="{{ asset('venues/venue1/2.png')}}" class="d-block w-100 rounded-4" alt="Image Slide">
      {{-- <div class="carousel-caption d-none d-md-block">
        <h5>Soccer Pro</h5>
        <p>Etihad vs DXB Strikers</p>
      </div> --}}
    </div>
     <!-- Image Slide 3 -->
     <div class="carousel-item">
      <img src="{{ asset('venues/venue1/3.png')}}" class="d-block w-100 rounded-4" alt="Image Slide">
      {{-- <div class="carousel-caption d-none d-md-block">
        <h5>Soccer Pro</h5>
        <p>Etihad vs DXB Strikers</p>
      </div> --}}
    </div>
     <!-- Image Slide 4 -->
     <div class="carousel-item">
      <img src="{{ asset('venues/venue1/4.png')}}" class="d-block w-100 rounded-4" alt="Image Slide">
      {{-- <div class="carousel-caption d-none d-md-block">
        <h5>Soccer Pro</h5>
        <p>Etihad vs DXB Strikers</p>
      </div> --}}
    </div>
  
    </div>
    <!-- Previous & Next buttons -->
    <button class="carousel-control-prev" type="button" data-bs-target="#myCarousel" data-bs-slide="prev">
      <span class="carousel-control-prev-icon" aria-hidden="true"></span>
      <span class="visually-hidden">Previous</span>
    </button>
    <button class="carousel-control-next" type="button" data-bs-target="#myCarousel" data-bs-slide="next">
      <span class="carousel-control-next-icon" aria-hidden="true"></span>
      <span class="visually-hidden">Next</span>
    </button>
  </div>
  
  <!-- Bootstrap Bundle with Popper -->
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
  <!-- CSS for Heart Icon -->
<style>
    .heart-icon {
        position: absolute;
        top: 10px;
        right: 300px;
        z-index: 1000;
    }
    .heart-icon i {
        font-size: 1.5rem;
        color: red; 
        cursor: pointer;
    }
    
</style>
<!-- jQuery -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<!-- JavaScript to handle click event on heart icon -->
<script>
    $(document).ready(function() {
        $('.heart-icon').click(function() {
            var heartIcon = $(this).find('i');
            if (heartIcon.hasClass('bi-heart')) {
                heartIcon.removeClass('bi-heart').addClass('bi-heart-fill')/* .css('color', 'red') */;
            } else {
                heartIcon.removeClass('bi-heart-fill').addClass('bi-heart')/* .css('color', 'white') */;
            }
        });
    });
</script>

I tried to change the class property using javascript and the css property but it’s not working.

PHP: cant pass an object into a function, it becomes a string

I’m trying to pass an object to a function in PHP to split a long function. The first example is the working way with the long funcion:

public function import() {
    $this->importSections();
}
public function importSections() {
    $reader = new PhpOfficePhpSpreadsheetReaderXlsx();
    $spreadsheet = $reader->load($this->_file);
    $sheet = $spreadsheet->getSheetByName('Sections');
    $highestRow = $sheet->getHighestDataRow(); // <- this works
    // ... //
}

However, I get the Error Call to a member function getHighestDataRow() on string on the above marked line if I try to split the function and pass the sheet like this:

public function import() {
    $reader = new PhpOfficePhpSpreadsheetReaderXlsx();
    $spreadsheet = $reader->load($this->_file);
    $sheet = $spreadsheet->getSheetByName('Sections');
    $this->importSections($sheet);
}
public function importSections($sheet) {
    $highestRow = $sheet->getHighestDataRow(); // <- Error
    // ... //
}

And if I explicitly pass it by reference like this..:

public function import() {
    $reader = new PhpOfficePhpSpreadsheetReaderXlsx();
    $spreadsheet = $reader->load($this->_file);
    $sheet = $spreadsheet->getSheetByName('Sections');
    $this->importSections($sheet);
}
public function importSections(&$sheet) {
    $highestRow = $sheet->getHighestDataRow(); // <- Error
    // ... //
}

…I get the error Argument #1 ($sheet) could not be passed by reference.

Can someone please explain what is going on here?

Install PHP 5.3.3 on Ubuntu [closed]

there,

I would like to know how to install php5.3.3 on my Ubuntu VM in 2024. I really need this specific version and not the latest version. I’ve got a Joomla project that has some problems and I want to transfer it to my VM. For that I need php version 5.3.3 but I don’t know how to install it.

I’ve tried some of the tricks ChatGPT gave me, but they don’t work. I know that the version is available on the php.net/releases site.I’ve tried a trick with “make” but either I get errors or it can’t find the file.

dealing with the checkbox and send to database

I have been using the code for sending the data into database when the checkbox is checked then it should send true to database. when unchecked and send then false should be shown.
in database I have used datatype enum p and a as its values and a is its default value.

<?php

if (isset($_POST['save'])) {
    $errors = []; // Initialize an empty errors array

    // Check if any attendance data was submitted
    if (!isset($_POST['attendance']) || !is_array($_POST['attendance']) || empty($_POST['attendance'])) {
        $errors[] = "No attendance data submitted. Please select student(s) and their status.";
    }

    // If no errors, proceed with processing attendance
    if (empty($errors)) {
        foreach ($_POST['attendance'] as $student_id => $status) {
            // Check if the checkbox is checked (present) or not (absent)
            $status = isset($status) ? 'p' : 'a'; // Present: 'p', Absent: 'a'
            $reason = isset($_POST['reason'][$student_id]) ? $_POST['reason'][$student_id] : 'Not Specified';

            // Prepare INSERT query with placeholders
            $sql = "INSERT INTO stds_attendance (student_id, status, reason) VALUES (?, ?, ?)";
            $stmt = mysqli_prepare($conn, $sql);

            if ($stmt) {
                mysqli_stmt_bind_param($stmt, 'sss', $student_id, $status, $reason);

                if (mysqli_stmt_execute($stmt)) {
                    echo "Attendance data for student $student_id saved successfully.<br>";
                } else {
                    $errors[] = "Error saving attendance data: " . mysqli_stmt_error($stmt);
                }

                mysqli_stmt_close($stmt);
            } else {
                $errors[] = "Error preparing statement: " . mysqli_error($conn);
            }
        }
    }

    // Display any accumulated errors
    if (!empty($errors)) {
        echo "<ul class='error-list'>";
        foreach ($errors as $error) {
            echo "<li>$error</li>";
        }
        echo "</ul>";
    }
}

?>

PHP preg_match to check if a character is contained while another not using lookahead [duplicate]

I need to check inside a given string, if a character is contained while another not e.g. It needs to contain ‘a’ but not ‘b’.

I tried with something like:

echo preg_match('/(?:a)(?!b)*$/','hi a good day')

I tried with the lookahead, but I am missing something … the first part matches the second does not because it should be valid for the length of all the string and not just for some.
So I tried also with

echo preg_match('/^(?:a)[^b]*$/','hi a good day');

and it does not match, what am I missing ?
( I know I could use strpos but I would like to use a regex approach ).