PHP CodeIgniter class not found

I have the following classes

applicationControllersAppointments.php

applicationcontrollersapiv2AppointmentsV2.php

From AppointmentsV2 I want to access Appointments class, I tried many ways not working
I tried almost every thing always not working

require (APPPATH.'/Controllers/Appointments.php');

The class dose not use name scpace

class AppointmentsV2 extends EA_Controller {}
class Appointments extends EA_Controller {}
class EA_Controller extends CI_Controller {)

Error:

Message: Class ‘Appointments’ not found

Random Story button tries to generate story 1-1000

The “Random Story” button tries to generate story 1-1000

argentina.html

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Stories</title>
    <link rel="stylesheet" href="../CSS/usa.css">
</head>
<body>
    <header>
        <h1>Stories</h1>
    </header>
    <main>
        <div id="content-wrapper">
            <div id="get-container">
                <input type="text" id="story-number" placeholder="Enter story number">
                <button id="get" type="button">Get Story</button>
                <button id="getRandom" type="button">Random Story</button>
            </div>
            <div id="story-container">
                <!-- Story content will be displayed here -->
                <div id="generated-text"></div>
                <button id="clear">Clear</button>
            </div>
        </div>
    </main>
    <script src="Scripts/argentina.js"></script>
</body>
</html>ript src="Scripts/argentina.js"></script>
</body>
</html>

argentina.js

document.addEventListener('DOMContentLoaded', function () {
    var totalStories = 1000;
    var currentStory = null;
    var storyContainer = document.getElementById('story-container');
    var contentWrapper = document.getElementById('content-wrapper');
    var storyNumberInput = document.getElementById('story-number');
    var getButton = document.getElementById('get');
    var getRandomButton = document.getElementById('getRandom');
    var clearButton = document.getElementById('clear');

    function clearStoryContainer() {
        if (storyContainer) {
            storyContainer.style.display = 'none';
            var generatedTextElement = document.getElementById('generated-text');
            if (generatedTextElement) {
                generatedTextElement.innerHTML = '';
            }
            if (contentWrapper) {
                contentWrapper.style.marginTop = '0px';
            }
            currentStory = null;
            storyNumberInput.value = ''; // Clear the input text
        }
    }

    function fetchStory(storyNumber) {
        clearStoryContainer();
        var xhr = new XMLHttpRequest();
        xhr.open('GET', 'PHP/argentina.php?story=' + storyNumber, true);
        xhr.onload = function () {
            if (xhr.status === 200) {
                if (storyContainer) {
                    storyContainer.style.display = 'block';
                    var generatedText = xhr.responseText;
                    var generatedTextElement = document.getElementById('generated-text');
                    if (generatedTextElement) {
                        generatedTextElement.innerHTML = parseAndStyleTitles(generatedText);
                    } else {
                        console.log('Generated text element not found.');
                    }
                    if (contentWrapper) {
                        contentWrapper.style.marginTop = '0';
                    }
                    currentStory = storyNumber;
                } else {
                    console.log('Story container element not found.');
                }
            } else {
                console.log('Error fetching story. Status code: ' + xhr.status);
                clearStoryContainer();
                if (xhr.status === 404) {
                    displayErrorMessage('Please enter a valid number between 1 and ' + totalStories + '.');
                } else {
                    displayErrorMessage('Error fetching story.');
                }
            }
        };
        xhr.onerror = function () {
            console.log('Network error while fetching story.');
            clearStoryContainer();
            displayErrorMessage('Network error while fetching story.');
        };
        xhr.send();
    }

    function displayErrorMessage(errorMessage) {
        if (storyContainer) {
            storyContainer.style.display = 'block';
        }
        var generatedTextElement = document.getElementById('generated-text');
        if (generatedTextElement) {
            generatedTextElement.innerHTML = errorMessage;
        }
        if (contentWrapper) {
            contentWrapper.style.marginTop = '60px';
        }
        currentStory = null;
    }

    function parseAndStyleTitles(text) {
        return text.replace(/[[(.*?)]]/g, function (match, title) {
            return '<span>' + title + '</span>';
        });
    }

    getButton.addEventListener('click', function () {
        var storyNumber = parseInt(storyNumberInput.value);

        if (!isNaN(storyNumber) && storyNumber >= 1 && storyNumber <= totalStories) {
            fetchStory(storyNumber);
        } else {
            displayErrorMessage('Please enter a valid number between 1 and ' + totalStories + '.');
        }
    });

    getRandomButton.addEventListener('click', function () {
        var randomStoryNumber = Math.floor(Math.random() * totalStories) + 1;
        fetchStory(randomStoryNumber);
    });

    clearButton.addEventListener('click', function () {
        clearStoryContainer();
    });

    storyNumberInput.addEventListener('keyup', function (event) {
        if (event.key === 'Enter') {
            getButton.click();
        }
    });
});

argentina.php

<?php
// Read the requested story number from the URL parameter
$storyNumber = $_GET['story'];

// Read the content of argentina.txt (relative to the location of this PHP file)
$storiesFile = file_get_contents('../../Stories/argentina.txt');

// Split the content into stories based on the unique delimiter (<!-- Unique delimiter separating stories -->)
$stories = preg_split('/<!-- Unique delimiter separating stories -->/', $storiesFile);

// Determine the actual number of stories
$actualTotalStories = count($stories);

if ($storyNumber >= 1 && $storyNumber <= $actualTotalStories) {
    // Check if the requested story exists
    $requestedStory = trim($stories[$storyNumber - 1]);
    $formattedStory = nl2br($requestedStory);
    echo $formattedStory;
} else {
    echo 'Error: Story not found.';
}
?>

I want to have it set to 1000 in the JavaScript because that’s the amount of stories that will be added in the end. But when I have 5 stories in the argentina.txt file I want the code to read 1-5, then when I add a new story I want it to read 1-6, etc.

How could I make this work? Would really appreciate some help on this!

PHP – Header function not redirecting to page

I am trying to make a program that connects to a database and inserts some information to a table.

`<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $forename = $_POST["forename"];
    $surname = $_POST["surname"];
    $contractedHours = $_POST["contractedHours"];
    $email = $_POST["email"];

    echo "Hello World";

    try {
        require_once "dbh.inc.php";

        $query = "INSERT INTO `employees`(`forename`, `surname`, `contractedHours`, `email`) VALUES (?, ?, ?, ?);";

        $stmt = $pdo->prepare($query);

        $stmt->bindParam(":forename", $forename);
        $stmt->bindParam(":surname", $surname);
        $stmt->bindParam(":contractedHours", $contractedHours);
        $stmt->bindParam(":email", $email);

        $stmt->execute();

        $pdo = null;
        $stmt = null;

        header("Location: ../test.php");

        die();
    } catch (PDOException $e) {
        die("Query Failed: " . $e->getMessage());
    }
} else {
    header("Location: ../test.php");
    exit;
}`

The database is currently unable to connect which is a separate problem but when the code is run, it always ends up in the else branch of the if statement. However, it leaves me on a white screen, without redirecting to the 'test.php' page. I have tried using obj_start() and obj_end() but these do not fix my issue. Any ideas how to solve this?

After update wordpress plugins, some fatal error occur

Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /var/www/html/dvice/wp-includes/class-wpdb.php:2067 Stack trace: #0 /var/www/html/dvice/wp-includes/class-wpdb.php(773): wpdb->db_connect() #1 /var/www/html/dvice/wp-includes/load.php(678): wpdb->__construct(‘xxxx’, ‘werewww..’, ‘hhhhhhh’, ‘localhost’) #2 /var/www/html/dvice/wp-settings.php(124): require_wp_db() #3 /var/www/html/dvice/wp-config.php(117): require_once(‘/var/www/html/a…’) #4 /var/www/html/dvice/wp-load.php(50): require_once(‘/var/www/html/a…’) #5 /var/www/html/dvice/wp-blog-header.php(13): require_once(‘/var/www/html/a…’) #6 /var/www/html/dvice/index.php(17): require(‘/var/www/html/a…’) #7 {main} thrown in /var/www/html/dvice/wp-includes/class-wpdb.php on line 2067

How to resolve this, i have update mysqli in my server

SQLSTATE [HY093]: Invalid parameter number: mixed named and positional parameters

I’m having a problem registering a user and getting an error [SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters

> select * from `verifications` where
> `{"role_name":"user","mobile":null,"email":"tesst@gmail`.`com","full_name":"test","status":"pending","access_content":true,"affiliate":false,"timezone":"Asia/Bangkok","created_at":1697102421,"id":1062}`
> = email and `expired_at` > 1697102421 and (`user_id` is null or exists (select * from `users` where `verifications`.`user_id` =
> `users`.`id`)) limit 1

(https://i.stack.imgur.com/YWiwN.png)[query error screen shot][1]
i use“`
Rocket LMS – Learning Management & Academy Script

error detail : https://flareapp.io/share/KPgWDwJP


Current PHP version 8.0


Can anyone help me shed some light upon this situation?


  [1]: https://i.stack.imgur.com/Y0ik9.png

Cakephp CMS Tutorial PaginatorComponent is deprecated, throws warnings

The Content Management Tutorial at cakephp throws deprecation errors concerning the paginator.

This code is the source for the warning.

<?php
// src/Controller/ArticlesController.php
namespace AppController;

use AppControllerAppController;

class ArticlesController extends AppController
{
    public function initialize(): void
    {
        parent::initialize();

        $this->loadComponent('Paginator');
        $this->loadComponent('Flash'); // Include the FlashComponent
    }

    public function index()
    {
        $articles = $this->Paginator->paginate($this->Articles->find());
        $this->set(compact('articles'));
    }

It generates the warning
Deprecated (16384) : PaginatorComponent is deprecated, use a CakeDatasourcePaginationNumericPaginator instance directly. /home/..../vendor/cakephp/cakephp/src/Controller/ComponentRegistry.php, line: 133

Found two hints to change the source. Remove the loadComponent and change the pagination method.

<?php
// src/Controller/ArticlesController.php
namespace AppController;

use AppControllerAppController;

class ArticlesController extends AppController
{
    public function initialize(): void
    {
        parent::initialize();
        $this->loadComponent('Flash'); // Include the FlashComponent
    }

    public function index()
    {
    // Paginate the ORM table.
    $this->set('articles', $this->paginate($this->Articles));
        $this->set(compact('articles'));
    }

Background for pagination 4.x cakephp doc pagination

send file with curl to yii2 controller

I want to send a file with curl by windows command line, to a yii2 controller.
My script for command line is like this:

curl  -X POST -F "file=@G:file.txt"  http://file.localhost/file-siakadbeta/upload

and my yii2 controller is like this:

 class FileSiakadbetaController extends Controller
 {
   public function actionUpload()
   {

    if ($_FILES && isset($_FILES['file'])) {
        $target_dir = "uploads/"; // Replace with your desired upload directory
        $target_file = $target_dir . basename($_FILES['file']['name']);
        
        // Check if the file already exists
        if (file_exists($target_file)) {
            return "File already exists.";
        } else {
            // Move the uploaded file to the target directory
            if (move_uploaded_file($_FILES['file']['tmp_name'], $target_file)) {
                return "File uploaded successfully.";
            } else {
                return "File upload failed.";
            }
        }
    } else {
        return "No file uploaded.";
    }  
  }
}

The problem is, i get response

Bad Request (#400)

I have try to send the curl command to plain php code (not use yii2 framework) and the upload code is working.

Any help?

Laravel Middleware add query string to incoming request

I currently have an integration with another system that has its own SDK. The SDK authenticates using query string parameters which is working fine. However, we are updating the integration to use more of our application but due to redirects it loses the query string needed.

We have a session variable that is set on an incoming request that we can use to flag when the query string should be appended but need this to be done at the highest level to prevent the need in checking this in multiple places. I have tried middleware but it doesn’t seem to add the query string.

Anyone have any ideas?

Created middleware and registered it. tried the following code:

URL::defaults(['test'=>'test']);
$request->merge(['test'=>'test']);
$request->fullUrlWithQuery(['test' => 'test']);

What is required is that an incoming request and subsequent redirects change from http://example.com/submissions into http://example.com/submissions?test=test

how to create clickable link to show specific Id Employee in Angular using Laravel API

working with Angular Front-end and Laravel Api to display data set of Employees details with title and lararies. Employee model one to many relationship with Title and Salary
employees.component.html

<table class="table">
    <thead>
        <tr>
            <th scope="col">#</th>
            <th scope="col">Employee Name</th>
            <th scope="col">Date of Birth</th>
            <th scope="col">Gender</th>
            <th scope="col">Hire Date</th>
        </tr>
    </thead>
    <tbody>
        <tr *ngFor="let emp of employee">
            <th scope="row">{{emp.emp_no}}</th>
            <td>{{emp.first_name}}</td>
            <td>{{emp.birth_date}}</td>
            <td>{{emp.gender}}</td>
            <td>{{emp.hire_date}}</td>

        </tr>
    </tbody>

</table>

and I have api route to display specific id Employee like this

//get specific employee
Route::get('employee/{id}','AppHttpControllersEmployeeController@getEmployeeById');

EmployeeController

 public function getEmployeeById($id) {
        $employee = Employee::with('titles','salaries')->find($id);
        if(is_null($employee)) {
            return response()->json(['message' => 'Employee Not Found'], 404);
        }
        return response()->json($employee::with('titles','salaries')->find($id), 200);
    }

angular data.service.ts for get employee by id is

getEmployeeById(id: string){
    return this.httpClient.get('http://127.0.0.1:8000/api/employee/'+id);
  }

now I need create a clickble link on the name colum of the Employee.component.ts file and redirect to new file to show spesific id emploee. then how could I do this?

Unable to execute an Excel macro using PHP on a Microsoft IIS server

I have a PHP application running on an IIS server using PHPSpreadSheet. Excel is installed on the server where the website is hosted. My main goal is to insert data from my database into Excel files for clients. It works for some, but not for others. The issue is that the files have contextual formatting that disappears once the file is saved, which seems to be a known problem. So, I tried a different approach. I created a temporary Excel file named ‘data.xlsm’ with a macro that automatically runs when the file is opened to insert the received data into the client’s Excel file.

My problem is that I can’t open the ‘data.xlsm’ file in my PHP code. If I double-click on it or open it with the server’s ‘cmd’, it works fine.

Cmd: "C:/Program Files/Microsoft Office/root/Office16/Excel.exe" C:/www/dunfreshSQ/FICHIERS/Data.xlsm

I tried reloading the file, modifying it, and then saving it with phpSpreadSheet, but nothing happens. I also attempted to execute the command that works with ‘cmd’, but nothing happens:

$command = '"C:/Program Files/Microsoft Office/root/Office16/Excel.exe" C:/www/dunfreshSQ/FICHIERS/Data.xlsm 2>&1';
$output = array();
$returnValue = null;
exec($command, $output, $returnValue);

I saw that you can run a macro using the PHP COM object, but the problem is that I get an error when I do:

$excel = new COM("Excel.application");

It can’t find the class, even though I have ‘php_com_dotnet.dll’ in my ‘ext’ folder and the extension is activated in ‘php.ini’.

HELP!!!”

How can I update the info from database but without updating image in PHP [closed]

I’m new here. I need to know the problem with these codes since I want to update blog content without image change but I’m stuck with this problem, can you help me to fix my code, please?

if (isset($_POST['edit_blog'])) {
        $title = mysqli_real_escape_string($config, $_POST['blog_title']);
        $body = mysqli_real_escape_string($config, $_POST['blog_body']);
        $filename = $_FILES['blog_image']['name'];
        $tmp_name = $_FILES['blog_image']['tmp_name'];
        $size = $_FILES['blog_image']['size'];
        $image_ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
        $allow_type = ['jpg', 'png', 'jpeg'];
        $destination = "upload/".$filename;
        $category = mysqli_real_escape_string($config, $_POST['category']);
        if (!empty($filename)) {
            if (in_array($image_ext, $allow_type)) {
                if ($size <= 2000000) {
                    $unlink = "upload/".$result['blog_image'];
                    unlink($unlink);
                    move_uploaded_file($tmp_name, $destination);
                    $sql3 = "UPDATE blog SET blog_title = '$title', blog_body = '$body', blog_image = '$filename', category = '$category', author_id = '$author_id' WHERE blog_id = '$blogID'";
                    $query3 = mysqli_query($config, $sql3);
                    if($query3) {
                        $msg = ['Update success', 'alert-success'];
                        $_SESSION['msg'] = $msg;
                        header('location:index.php');
                    } else {
                        $msg = ['Failed, try again', 'alert-danger'];
                        $_SESSION['msg'] = $msg;
                        header('location:index.php');
                    }
                } else {
                    $msg = ['Image should be not greater than 2 MB', 'alert-danger'];
                    $_SESSION['msg'] = $msg;
                    header('location:index.php');
                }
            } else {
                $msg = ['This type of image file is not allowed (only jpg, png and jpeg accepted)', 'alert-danger'];
                $_SESSION['msg'] = $msg;
                header('location:index.php');
            }
        } else {
            $sql3 = "UPDATE blog SET blog_title = '$title', blog_body = '$body', category = '$category', author_id = '$author_id' WHERE blog_id = '$blogID'";
            $query3 = mysqli_query($config, $sql3);
            if($query3) {
                $msg = ['Update success', 'alert-success'];
                $_SESSION['msg'] = $msg;
                header('location:index.php');
            } else {
                $msg = ['Failed, try again', 'alert-danger'];
                $_SESSION['msg'] = $msg;
                header('location:index.php');
            }
        }
    }

I need to know the problem of these codes about the update without image change:

else {
$sql3 = “UPDATE blog SET blog_title = ‘$title’, blog_body = ‘$body’, category = ‘$category’, author_id = ‘$author_id’ WHERE blog_id = ‘$blogID'”;
$query3 = mysqli_query($config, $sql3);
if($query3) {
$msg = [‘Update success’, ‘alert-success’];
$_SESSION[‘msg’] = $msg;
header(‘location:index.php’);
} else {
$msg = [‘Failed, try again’, ‘alert-danger’];
$_SESSION[‘msg’] = $msg;
header(‘location:index.php’);
}
}

PHP verify signed string using public certificate

We’re working on a project where we receive data which contains a “signature”. This is known parts of the data (UTF8) which have been signed by the sender using the private x.509 certificate and base64 encoded. As part of the data we receive their public certificate in Base64.

We’ve been researching this endlessly but can only find articles on verifying the certificate, but this isn’t what we need to do.

So, if we have something like:

$unsigned_data = "123456789";
$senders_certificate = "MIIHpTCCBY2gAwIBAgIQBZXrUf3M67aS2TO7RhrAIjANBgkqhkiG9w0BAQsFADBcMQswCQYDVQQGEwJVUzEXMBUGA1UEChMORGlnaUNlcnQsIEluY..."; //etc etc
$posted_signature = "3BJcFbln7j5mUHdFIt9wbHlSi1McpmP0hCR5g6NXhBw3ffSGzXPtgg..."; //etc etc

… how do we check the $posted_signature is what it should be?

Prevent conversion of & into & when saving to database

I store translation memory contents in a MySQL database. Some segments contain tags, they can be TMX format tags or HTML tags. This is what a segment with TMX tags looks like in the database:

enter image description here

I use htmlentities to display the tags as they are in the browser-based editor. I then use jQuery to colour them red:

$(".editable").html(function(_, html) {
   return html.replace(/(&lt;.+?&gt;)/gm, '<span class="text-danger">$1</span>');
});

Previously, I used to accomplish the same using PHP but without htmlentities:

$sourceText = preg_replace('/<(.*?)/>/', "<span style='color:red'>&lt;$1&gt;</span>", $sourceText);
$targetText = preg_replace('/<(.*?)/>/', "<span style='color:red'>&lt;$1&gt;</span>", $targetText);

It doesn’t really matter which method I use to colour the tags. The segments look like this when displayed in my browser editor:

enter image description here

If I click the table cell that contains the source or target text, it opens for editing and looks like this:

enter image description here

When I click “Save”, the Javascript makes an Ajax call to a simle PHP script to save the changes into the database. This is the step where something causes the ampersand in the angle brackets html entities delimiting the tags to be converted to &amp;. This is what the segment looks like when saved in the database (look at the right half):

enter image description here

To be expected, when the edited segment is displayed in the browser in view mode again, the jQuery function that colours the tags in red no longer works – because the regex can no longer capture them, becuse the & is now &amp;. And it looks like this:

enter image description here

And it looks like this when opened for editing:

enter image description here

It gets better! When I save this again, the & in &amp; is itself converted to &amp; and it now looks like this in the database:

enter image description here

This can go on ad nauseam.

My question is: How can I prevent the conversion of & into &amp; when saved into the database?

Nothing in the Javascript that converts the table cell to textarea seems to be responsible for this conversion. Below is the entire JS code:

let table = document.getElementById('editable');

let editingTd;

table.onclick = function(event) {
    /* if 'table.ondblclick' is used, this requires double-clicking the OK and Cancel buttons, too */
    // 3 possible targets
    let target = event.target.closest('.edit-cancel.btn.btn-danger,.edit-ok.btn.btn-success,.editable');

    if (!table.contains(target)) return;

    if (target.className == 'edit-cancel btn btn-danger') {
        finishTdEdit(editingTd.elem, false);
    } else if (target.className == 'edit-ok btn btn-success') {
        finishTdEdit(editingTd.elem, true);
    } else if (target.nodeName == 'TD') {
        if (editingTd) return; // already editing
        makeTdEditable(target);
    }
};

function makeTdEditable(td) {
    editingTd = {
        elem: td,
        data: td.innerHTML
    };

    td.classList.add('edit-td'); // td is in edit state, CSS also styles the area inside

    let textArea = document.createElement('textarea');
    textArea.style.width = td.clientWidth + 'px';
    textArea.style.height = td.clientHeight + 'px';
    textArea.className = 'edit-area';

    textArea.value = td.innerHTML;
    td.innerHTML = '';
    td.appendChild(textArea);
    textArea.focus();

    td.insertAdjacentHTML("beforeEnd",
    '<div class="edit-controls"><button class="edit-ok btn btn-success">SAVE</button><button class="edit-cancel btn btn-danger">CANCEL</button></div>'
    );
}

function finishTdEdit(td, isOk) {
    if (isOk) {
        td.innerHTML = td.firstChild.value;
        id = td.getAttribute("data-id");
        segmentID = td.getAttribute("data-segmentID");
        content = td.innerHTML;
        fileName = td.getAttribute("data-fileName");
        console.log('saved '+id+' successfully: '+td.innerHTML);
        // AJAX to save edit to DB
        $.ajax({
            type: "POST",
            url: "tmx_update.php",
            data: {
                fileName: fileName,
                id: id,
                content: content
            }, 
            success: function(data) {
                $("#status-report-"+segmentID).html(data);
            }
        });
        
    } else {
        td.innerHTML = editingTd.data;
    }
    td.classList.remove('edit-td');
    editingTd = null;
}