send a JSON data object to the server using Javascript XMLHttpRequest?

Im conding in php and would like to send the information on the calender to the controller. I think my MVC is set up correctly and i get a status 200 that the data is sent as an object (see photo) but when i want to receive it in the controller i keep getting NULL. My project does not have a .htacess and uses a basic router. I run everthing form my docker container. The idea is click a tile and sent the object information to the controller so i can add it to a shoppingcart. Any help is appreciated

this is the code that i was trying in my javascript

Javascript code. Calendar.js

document.addEventListener('DOMContentLoaded', function() {
document.querySelectorAll('.event').forEach(function(eventElement) {
    eventElement.addEventListener('click', function() {
        var eventDetails = {
            name: this.getAttribute('data-name'),
            startTime: this.getAttribute('data-start-time'),
            endTime: this.getAttribute('data-end-time')
        };
        // Send AJAX request to the server
        var xhr = new XMLHttpRequest();
        xhr.open('POST', 'http://localhost/jazz');
        xhr.setRequestHeader('Content-Type', 'application/json');
        xhr.onreadystatechange = function() {
            if (xhr.readyState === XMLHttpRequest.DONE) {
                if (xhr.status === 200) {
                    console.log(eventDetails);
                    console.log('Request successful');
                } else {
                    console.error('Request failed');
                }
            }
        };
        xhr.send(JSON.stringify(eventDetails));
    });
});

});

This is my controller where i want to receive the information but the vardump is empty and it does not go in the if-statement
jazzcontroller.php

This is my calendar.php where i fill the information
calendar.php

Here is some extra information to give some clarification
Chrome console object eventDetails
headers of the object

Thanks again.

how to remove product category slug but show all the slug category terms and the sub-category woocommerce

so I followed this post, and it worked fine. but not with sub-categories.

the first of 2nd sub categories works fine, but if the sub-category more than 2, it return 404. take a look at this :

  • I have this breadcrumb, each can be clicked (cause it’s a sub-category)
  • Like I said, the first of 2nd sub categories can be clicked, but the rest, it returns 404. the first of 2nd is test1 and test2-productcat (home is not count).
  • enter image description here

so far I’ve tried :

  • var_dump the first breadcrumb (test1) and it shows like this :
array(2) { ["page"]=> string(0) "" ["name"]=> string(5) "test1" }
  • var_dump the second breadcrumb (test2-productcat) :
array(1) { ["attachment"]=> string(16) "test2-productcat" }
  • after that it just return 404, like this
array(1) { ["error"]=> string(3) "404" }

why it behave like this? I mean the first is return page, second return attachment? is it possible to do like I want to achive?

thank you.

Reload an included part in a PHP index page [closed]

I have an index.php page which loads different includes based on parameters. Only one of the includes shall have an automated updating part to see new info.

In the head of the index page I have

<script type="text/javascript" src="js/jquery.js">

to load the jquery lib.

In the inc-part that keeps the news I have

echo '<script>
var $incomingNews = $("#incomingNews");
setInterval(function () {
    $incomingNews.load("index.php #incomingNews");
}, 60000); 
</script>';

The included page has the info-block within a div:

 echo '<div id="incomingNews">';
 <!-- some code-->
 echo '</div>;

I was hoping that the age would reload the parts inside the div every minute … obviously something is wrong in the code. Any hints?

WooCommerce – Is there a way to take a one-off payment, and setup a direct debit in the same checkout?

I’m attempting to build a website whereby the user needs to pay a one-off fee (setup fee) for a product and once that’s done, then setup a direct debit payment. We’re in the process of contacting various payment gateway providers to ensure they support both payment types but in terms of WordPress/WooCommerce is involved.

Is there a way to integrate this at all, is it something that’s quite difficult and doesn’t work very well or is it simply a lot of coding that needs to be done and can’t be done with a mixture of a few plugins?

Any help would be appreciated. Thanks!

Building an extension php .dll (ext_http)

I had already asked a question about this (Question extension relative) so the only solution was to compile the .dll myself on Windows.
I want to compile the .dll for the PECL http extension on Windows.

However, I clearly can’t build it with all the tutorials I see, I always have problems with version conflicts between all the software I need to download.

From all the tutorials I’ve been watching I’ve followed this method but I must be doing something wrong:

– Download Visual Studio Build Tools 2019 (https://my.visualstudio.com/Downloads?q=Visual%20Studio%202019) which would allow you to compile
– First take the php version you want and download “Development package” (or the debug pack). I took the php version 8.1.26
– Declare the root folder path in (e.g. “C://php-8-1”) the PATH in the user’s environment variables
– Download the PECL extension source folder (i.e. ext_http) and extract it

After all these downloads I start the procedure:

– Open the extracted PECL extension folder with visual studio’s native terminal (“x86_x64 Cross Tools Command Prompt for VS 2019”) as administrator.
– Launch : phpize then configure
After launch configure an error : “bison.exe is required” The only viable version I found was GnuWin32 (Bison: https://sourceforge.net/projects/gnuwin32).

After relaunch configure, another error appeared saying that bison.exe had to be of a more recent version, or at least 3.0.0, and the only existing Windows setup for Bison was max 2.4.1.

From then on, it was never-ending: we had to compile the bison.exe for Windows ourselves, and that’s when I started to give up …

If anyone has a viable tutorial or say me if I misunderstood something, I’d love it.

Thanks in advance!

My PHP code cant working due to javascript toggle password visibility [closed]

login button no work due to js code,i dont know how to fix it.

<?php
// process_login.php
include 'functions.php';

    session_start();


    if ($_SERVER["REQUEST_METHOD"] == "POST") {
        // Database connection parameters
        $host = 'localhost'; // usually 'localhost'
        $username = 'root';
        $password = '';
        $database = 'kasrifqi';

        // Create a connection
        $conn = new mysqli($host, $username, $password, $database);

        // Check connection
        if ($conn->connect_error) {
            die("Connection failed: " . $conn->connect_error);
        }

        // Retrieve username and password from the form
        $username = $_POST['username'];
        $password = $_POST['password'];

        // Use prepared statement to prevent SQL injection
        $loginQuery = "SELECT * FROM users WHERE username = '$username' AND password = '$password'";
        $result = $conn->query($loginQuery);
        $arr = [];
        while ($row = $result->fetch_assoc()) {
            $arr = $row;
        }



        // Check if the user exists
        if ($result->num_rows > 0) {
            // Fetch the user data
            $_SESSION['username'] = $username;
            header("Location: index.php");
        }
    }
    ?>

    <html>
    <head>
        <meta charset="utf-8">
        <title>Login</title>
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css" />
        <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.1/css/all.css">
        <script src="mata.js" defer></script>
        <link href="layout/stylez.css" rel="stylesheet" type="text/css">
    </head>
    <body>
        <div class="login">
            <h1>Sign In</h1>
            <form action="process_login.php" method="post"> <!-- Changed form action -->
                <label for="username">
                    <i class="fas fa-user"></i>
                </label>
                <input type="text" name="username" placeholder="Username" id="username" required>
                <label for="password" class="kunci">
                    <i class="fas fa-lock "></i>
                </label>
                <p>
                <input for="fieldpass" type="password" name="password" placeholder="Password" id="password" required>
            
                <i class="bi bi-eye-slash logo" id="togglePassword"></i>
                
            </p>
                <input type="submit" value="Login">
            </form>
            <p style="text-align: center; margin-top: 10px; font-size: 14px; display: flex; justify-content: center;">
    Belum punya akun? Daftar&nbsp;<a href="register.php" style="text-decoration: none; color: #3274d6;">Disini</a>
</p>

        </div>
        
    </body>
    </html>

here is my js

document.addEventListener("DOMContentLoaded", function() {
    const togglePassword = document.querySelector("#togglePassword");
    const password = document.querySelector("#password");

    togglePassword.addEventListener("click", function () {
        // Toggle the type attribute of the password input
        password.type = password.type === "password" ? "text" : "password";
        
        // Toggle the eye icon
        togglePassword.classList.toggle("bi-eye");
        togglePassword.classList.toggle("bi-eye-slash");
    });

    // Prevent form submission
    const form = document.querySelector("form");
    form.addEventListener('submit', function (e) {
        e.preventDefault();
    });
});

i just want to fix the login button,but i cannot fix it help

about linking multiple pages in side nav bar and using include to use that side nav bar in those multiple pages in php [closed]

  <!-- Sidebar Start -->
        <div class="sidebar pe-4 pb-3">
            <nav class="navbar bg-secondary navbar-dark">
                <a href="index.php" class="navbar-brand mx-4 mb-3">
                    <h3 class="text-primary"><i class="fa fa-user-edit me-2"></i>RE:ZERO</h3>
                </a>
                
                <div class="navbar-nav w-100">
                <a href="index.php" class="nav-item nav-link active"><i class="bi bi-house me-2"></i>home</a>
                <a href="./re-zero/sidenav/search/search.php" class="nav-item nav-link"><i class="bi bi-search me-2"></i>search</a>
                <a href="./re-zero/sidenav/bookmarks/bookmarks.php" class="nav-item nav-link"><i class="bi bi-bookmark-star me-2"></i>bookmarks</a>
                <a href="./re-zero/sidenav/anime-openings/ao.php" class="nav-item nav-link"><i class="bi bi-music-note-list me-2"></i>anime openings</a>
                <a href="./re-zero/sidenav/genre/genre.php" class="nav-item nav-link"><i class="fa fa-th me-2"></i>genre</a>
                <a href="./re-zero/sidenav/news/news.php" class="nav-item nav-link"><i class="bi bi-newspaper me-2"></i>news</a>
                    <div class="nav-item dropdown">
                        <a href="G:xampphtdocsre zerosidenavbroswebrowse.php" class="nav-link dropdown-toggle" data-bs-toggle="dropdown"><i class="bi bi-folder me-2"></i>broswe</a>
                        <div class="dropdown-menu bg-transparent border-0">
                            <a href="" class="dropdown-item">popular</a>
                            <a href="" class="dropdown-item">New</a>
                            <a href="" class="dropdown-item">alphabetical</a>
                        </div>
                    </div>
                    <a href="G:xampphtdocsre zerosidenavsearchsearch.php" class="nav-item nav-link"><i class="bi bi-gear me-2"></i>Settings</a>
                   
        
                    </div>
                </div>
            </nav>
        </div>
        <!-- Sidebar End -->


        <!-- Content Start -->
        <div class="content">


<!-- Navbar Start -->
<nav class="navbar navbar-expand bg-secondary navbar-dark sticky-top px-4 py-0">
    <a href="index.php" class="navbar-brand d-flex d-lg-none me-4">
        <h2 class="text-primary mb-0"><i class="fa fa-user-edit"></i></h2>
    </a>
    <a href="#" class="sidebar-toggler flex-shrink-0">
        <i class="fa fa-bars"></i>
    </a>
    <div class="navbar-nav align-items-center ms-auto">
        <div class="nav-item dropdown">
            <a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown">
                <i class="fa fa-bell me-lg-2"></i>
                <span class="d-none d-lg-inline-flex">Notification</span>
            </a>
            <div class="dropdown-menu dropdown-menu-end bg-secondary border-0 rounded-0 rounded-bottom m-0">
                <a href="#" class="dropdown-item">
                    <h6 class="fw-normal mb-0">Profile updated</h6>
                    <small>15 minutes ago</small>
                </a>
                <hr class="dropdown-divider">
                <a href="#" class="dropdown-item">
                    <h6 class="fw-normal mb-0">New user added</h6>
                    <small>15 minutes ago</small>
                </a>
                <hr class="dropdown-divider">
                <a href="#" class="dropdown-item">
                    <h6 class="fw-normal mb-0">Password changed</h6>
                    <small>15 minutes ago</small>
                </a>
                <hr class="dropdown-divider">
                <a href="#" class="dropdown-item text-center">See all notifications</a>
            </div>
        </div>
        <div class="nav-item dropdown">
            <a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown">
                <img class="rounded-circle me-lg-2" src="img/user.jpg" alt="" style="width: 40px; height: 40px;">
                <span class="d-none d-lg-inline-flex">John Doe</span>
            </a>
            <div class="dropdown-menu dropdown-menu-end bg-secondary border-0 rounded-0 rounded-bottom m-0">
                <a href="#" class="dropdown-item">My Profile</a>
                <a href="#" class="dropdown-item">Settings</a>
                <a href="#" class="dropdown-item">Log Out</a>
            </div>
        </div>
    </div>
</nav>
<!-- Navbar End -->

code of my nav bar im using this to include in navbar in different pages of my code

<!-- head data stats here -->
<?php
include 'include files/navbar.php';
?>
<!-- head data ends here -->

image for the reference i got all include files in in include folder which i’m using to include he navbar in index.php and all files in side nav section
im currently using bootstrap

im tried using absolute paths which makes navbar stop functioning and and relative path doesn’t seems to function

Couldn’t upload image file in the website after migration to another hosting platform. Image file name is visible in the database. Using PhP laravel [closed]

I have changed my website to another hosting platform hostinger. I uploaded all the back up file and imported the database also. The website is working fine now. But have one issue that i tried to upload an image in my website and it’s not working. I checked the database and i can see the image file name in the database but the image is not visible in the website also The image is not stored in storage/app/ Why? . I am using Php laravel

I checked the file permissions and image path file. Everything is fine but couldn’t resolve the issue

composer and php poblem when I try to run

Good day! I needed to run a system locally in my laptop. I’m using XAMPP, MYSQL Workbench. Microsoft Visual Studio Code and Composer software. Upon typing “php artisan serve;” in the VS Code, I encountered an error saying

PS C:xampphtdocsdoclinkplus_v2> php artisan serve;
PHP Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version “>= 8.2.0”. You are running 8.0.30. in C:xampphtdocsdoclinkplus_v2vendorcomposerplatform_check.php on line 24

Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version “>= 8.2.0”. You are running 8.0.30. in C:xampphtdocsdoclinkplus_v2vendorcomposerplatform_check.php on line 24
PS C:xampphtdocsdoclinkplus_v2>

Should I download a different php version? Please help me solve this.

I tried editing the line of code that was mentioned in the error message but it still not working.

Start a PHP server from terminal for running PHP File on Rasperry Pi

I have PHP and Apache2 installed on my Raspberry Pi, that works. But, I dunno how to run a server and connect to it from it’s IP(http://192.168.1.25:22). And when I try another port, it says [Sat Mar 9 09:32:37 2024] Failed to listen on 192.168.1.25:80 (reason: Address already in use).

And : [Sat Mar 9 09:33:49 2024] PHP 7.4.33 Development Server (http://192.168.1.25:22) started

I tried those techniques, like php -S 192.168.1.25:22 router.php but does not work, maybe port error ? I createda router, tried without router.

Add class to WordPress image HTML elements

I need to style the element that goes around images embedded in a post
but as far as I can tell there is no way to automatically add a class to it or target <div>s with an <img> inside only without using jQuery or something.
And there is another condition that automatically add <div>HTML elements, when embedding two pictures.

<div class="sideBySide">
 <img src="#" alt="">
 <img src="#" alt="">
</div>

I have no clue and solve my problem

$_FILES empty after submit

$_FILES empty after form submit

I’m doing a little project where the user can upload multiple images from a simple form.
When I submit the form I go in a service page where I must save the images, but this not working.
So, I tried to print $_FILES, and I saw that it’s empty. Where is the mistake?

This is the HTML code with Boostrap:

<form action="salvataggio-foto.php" method="post" enctype="multipart/form-data">
  <div class="mb-3">
     <input class="form-control" type="file" id="images" name="images[]" multiple>
  </div>
  <button type="submit" class="btn btn-primary" name="invia">Carica</button>
</form>

In the service page, I have a simple print_r($_FILES).

Someone can helps me? Thank you so mutch 🙂