How to show boolean false whenever the query is false with PDO [duplicate]

function run($values = array()){
    switch($this->query_type){
        case 'select':
           // return $this->query;
           echo 1;
            $stm = self::$con->prepare($this->query);
            echo 2;
            if($stm){
                echo 5;
                if($stm->execute($values)) {
                    
                    echo 4;
                    $data = $stm->fetchAll(PDO::FETCH_ASSOC);
                    if (is_array($data) && count($data) > 0) {
                        return $data;
                    }
                }else{
                    echo 6;
                }
           
            }
            break;
           
        case 'insert':
            self::$con->query($this->query);
            return true;
        case 'update':
            $stm = self::$con->prepare($this->query);
            $stm->execute($values);
            return false;
        case 'delete':
            $stm = self::$con->prepare($this->query);
            $stm->execute($values);
            return false;
        default:
            return false;

    }
    return false;
}`

How can i get false whenever that query fails i.e when some one who is not i db is trying to login?

PhP & Ajex | DB Records not showing after selecting YEAR from DropDownList

Please see attached image for details.
enter image description here
Brief description

  1. User click “View”
  2. User select “Year”
  3. Show all records of that “Year”

For Step 2, when user click “Select Year”, the whole page refresh, which goes back to Step 1.
My intention was to use ajax to display the records, but I’m not sure where the error was.

There are 2 php files:

A) order_view.php

This php shows up to step 2.

B) order_view_ByYear.php

At step 3 after user clicks “Select Year”, use ajax to display the records at the bottom.


A) order_view.php

    <script type="text/javascript">
function submitYear(sno)
{
    var cusid=sno;
    var yearSelDD=document.getElementById("selectYear");
    var yearSel = yearSelDD.options[yearSelDD.selectedIndex].value;
    alert("cusid = " + cusid + " yearSel = " + yearSel);
    $.ajax({
            type:'POST',
            url:'order_view_ByYear.php',
            data:{
                cusid:cusid,
                yearSel:yearSel,
                wrapper:"testing"
            },
            //If successful, which part of webpage to change?
            success: function(result)
            {
                $('#showOrders').html(result);
            }  
    }); 
}
</script>

...
some codes
...

//==============================  Display that User's Orders using ajax ==============================  
    $sql2 = $mysqli->query("select * from orders where customerid='$cusid' ORDER BY orderid DESC");
    if ($sql2->num_rows > 0) {
        while ($row2 = $sql2->fetch_assoc()) {
            
            // Populate the YearArray() DropDownList
            $rowYear = date('Y', strtotime($row2["date"]));
            if($YearToAdd != $rowYear)
            {
                $YearToAdd = $rowYear;
                array_push($YearArray, $YearToAdd);
            }
        }
    }
?>
            <table><tr><td>
            <form method="post">
                <select>
                    <?php

                    // Iterating through the YearArray()
                    foreach($YearArray as $item){
                        echo "<option value='$item'>$item</option>";
                    }
                    ?>
                </select>
                <input type="submit" value="Select Year" id="selectYear" class="send" onClick="javascript:submitYear($ssno)"/>
            </form>
            </td></tr></table>
            <br/>
<?php
    echo "<div id="showOrders"></div>";

...
some codes
...

B) order_view_ByYear.php

<?php
error_reporting(0);
include "../database_connection.php";
$cusid    = $_POST['cusid'];
$YrSelect  = $_POST['yearSel'];

echo "CustID = ". $cusid . " Year = " . $YrSelect;

?>

I added an ALERT, but no Alert happened after clicking button “Select Year”.
My expected result is it should echo the 2 variables CustID & Year at the bottom.
Instead, the Whole page refresh itself and goes back to Step 1.

Much Appreciated.

Getting a warning message of Array to string conversion in php

Hi i am trying to check for the uniqueness of username in a page, but whenever i am running my code it either gives error or a warning message of Warning: Array to string conversion in C:xampphtdocslogin pcprocess_Signup.php on line 22

Code for my php is as follows:

$mysqli = require __DIR__."/database.php";

$sql = "INSERT INTO user_info (uname,pass,email)
        VALUES (?,?,?)";

$stmt=$mysqli->stmt_init();

if(! $stmt->prepare($sql)){
    echo("SQL error: " . $mysqli->error);
}

$sql1= "SELECT 1 FROM user_info (uname, pass, email) WHERE uname=$_POST('uname')";

$sql2= "SELECT 1 FROM user_info (uname, pass, email) WHERE email=$_POST('email')";


if($sql1>=1){
    echo "User Exists!";
}elif($mysql2>=1){
    print_r("Email Exists"); # in this line also i get an error i.e., i can not put ';' here
}
else{

    $stmt->bind_param("sss",
                  $_POST["uname"],
                  $_POST["password"],
                  $_POST["email"]);

    if($stmt->execute())
        echo "SignUp Successfull";
}


$result=$stmt->get_result();

The name of the database is login_cred and the name of the table is user_info, can anyone please tell how to remove this error/ warning sign.
The field names in the user_info table are id, uname, pass, email where id is primary key, uname and email are unique.
I would be highly grateful for your help.

How to access the static property in php? [duplicate]

How we access the static property with creating its class object with -> (arrow)  operator ?
OR
How to access static property without scope resolution operator (::) ?
How we access the static property with creating its class object with -> (arrow)  operator ?
OR
How to access static property without scope resolution operator (::) ?
<?php
class Foo
{
    public static $my_static = 'foo';

    public static function staticValue() {
        return self::$my_static;
    }
}

class Bar extends Foo
{
         public static function fooStatic();
    {
         return parent::$my_static;
    }

        public function barStatic(); 
    {
        return parent::$my_static;
    }
}


    Bar::fooStatic();
    $foo = new Foo();
    print $foo->staticValue() ." this is foo static". "n";
    print $foo->$my_static . "n";      // Undefined "Property" my_static 

?>

Change the key name of array validation error in Laravel

Here this is my form input (array)

enter image description here

I’m trying to validate the id field of this array of objects.

enter image description here
The error message return the key name as dummy_answers.0.id i want to change this to dummy_answers (without the key parameters with it).

enter image description here

Here is my piece of validation rules.

Requirement is want to change error field key name dummy_answers.0.id to dummy_answers .

Generate random numbers without repeat and sequence

I want to generate a random 4 digit pin without repeat and sequence numbers. I have tried the below code but it only preventing repeat numbers, it is still returning sequence numbers.

function randomGen($min, $max, $quantity) {
    $numbers = range($min, $max);
    shuffle($numbers);
    return array_slice($numbers, 0, $quantity);
}

$random = randomGen(1,9,4); 

$random_no = "";
foreach($random as $int){
 $random_no.=$int;   
}

$random_no = intval($random_no);

expected output : 4759

Should not be like this 5537 and 7312

Numbering invoices yearly with SQL and PHP

I’m a beginner in SQL and I tried looking for an answer without any luck.

I would like to generate invoice numbers automatically with the following distinctions:

  • I have 2 different structures invoicing
  • I would like to avoid any numbering issue, for example not having a missing invoice number if something gets altered (ex: 1, 2, 4, 5, 8, 9 …)
  • I would like them to be reset each year, so the numbering starts back to 1 every year for each structure :

ex: ENG_2022_1, ENG_2022_2 … ENG_2023_1

ex: FR_2022_1, FR_2022_2, FR_2022_3, … FR_2023_1

I have thought of setting a field with auto-increment, but that wouldn’t work with the structure and year distinctions unless there’s a workaround?

The other solution would be to get the year and structure before invoicing, and comparing it with a SQL MAX of the invoice number, before numbering but i’m not sure how good that solution?

Any help would be greatly appreciated

Delete function in my code is not working [closed]

This code in the delete function is not working properly. The code seems fine and no error but doesn’t execute properly in the system I am making. Please help me with this issue. Thank in advance.
I tried checking the SQL query in the database but the integrated in PHP, it is not working.

Here is my code:

if (isset($_GET['delete_id'])) {
$delete_id = $_GET['delete_id'];
$delete_sql = "DELETE FROM employees WHERE employee_id = $delete_id";
$delete_result = mysqli_query($connect, $delete_sql);
if (!$delete_result) {
  echo "<script>alert('Employee deletion failed.')</script>";
} else {
  echo "<script>alert('Employee deleted successfully!')</script>";
}
  echo "<script>window.location.href='employee_list.php'</script>";
}

<a href="employee_list.php?delete_id=<?php echo $row["employee_id"];?>" onClick="return   confirm('Are you sure you want to delete?')"><i class="glyphicon glyphicon-trash" style="font- size:16px;color:red;"></i></a>

Updating database from an array of input in PHP

  $patient_number = $_GET['patient_number'];
    $quer="SELECT * FROM prescription WHERE patient_number='$patient_number'";
    $resul=mysqli_query($connect,$quer);
    while ($ro=mysqli_fetch_array($resul)){
        $medicine_name = $ro['medicine_name'];
        $query = "UPDATE medicine SET quantity=$quantity WHERE medicine_name ='$medicine_name'";//line 28
        $res = mysqli_query($connect,$query);
    }

The error Warning: Array to string conversion in C:wamp64wwwHMSpharmacyaction.php on line 28 whenever I run my codes

How to pass a value to a php variable?

I’m currently working on a library system and I encountered a problem of mine which I’ve encoutered for the first time. When I displayed all the books that are currently in the library, I loop them to tables using php. Now, I want to pass the ISBN value of a current column to a variable and maybe use it to run a query to display information of a certain book. Below is the div part of my code.

    <div class="search-result">
        <table cellspacing="0">
            <tr>
                <th>ISBN</th>
                <th>BOOK TITLE</th>
                <th class="authorName">AUTHOR NAME</th>
                <th>SERIES</th>
                <th></th>
            </tr>

            <tr>
                <?php
                    while($row = mysqli_fetch_assoc($query)){
                ?>
                    <td><?php echo $row['ISBN'] ?></td>
                    <td><?php echo $row['Title'] ?></td>
                    <td><?php echo $row['Author'] ?></td>  
                    <td><?php echo $row['Series'] ?></td>
                    <td><a class="borrow-button" href="view.php">BORROW</a></td>
            </tr>
            <?php } ?>
        </table>
    </div>

I’ve not tried anyting solution because I can’t find on the internet what I’ve been looking for. I hope someone can help me

Routing error in Laravel resulting in: Call to undefined method ReflectionUnionType::getName()

Currently, I am writing tests for my Laravel application. However, one test fails and I don’t know why or how to solve it. I am running on Laravel 10 and PHP 8.2.3.

I have products and posts. Both models are morphed to the table and model comments because a user can write a comment under a product and under a post.

This is my route for the index function of the comments for either a product or a post with a given id:

Route::get('/comments/{commentableType}/{commentableId}', [CommentController::class, 'index'])->name('comments.index');

In the following, you will see my RouteServiceProvider. Here you can see, how I have binded the commentableType and commentableId. The strange thing now is, when I dd the line (new $model)->where('id', $id)->firstOrFail(); the correct product or post for the given idis being returned. Therefore, the route binding should be correct, I guess.

class RouteServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        $this->routes(function () {
            Route::middleware('api')
                ->prefix('api/v1')
                ->namespace($this->namespace)
                ->domain(config('app.domain'))
                ->group(base_path('routes/api/comment.php'));
        });

        // Defines a pattern for categoryType
        Route::pattern('categoryType', 'product|post');

        // Returns the id of the product or post
        Route::bind('commentableId', function ($id) {
            $type = app()->request->route('commentableType');
            $models = ['product' => Product::class, 'post' => Post::class];
            $model = $models[$type];
            return (new $model)->where('id', $id)->firstOrFail();
        });
    }
}

This is my CommentController@index function:

public function index(IndexCommentRequest $request, String $commentableType, Product | Post $commentableModel): JsonResponse
{
    $comments = $request->perform($commentableType, $commentableModel);

    return $this->successWithPayload(new CommentResource($comments));
}

And this is my IndexCommentRequest file

class IndexCommentRequest extends FormRequest
{
    public function authorize(): bool
    {
        return true;
    }

    public function rules(): array
    {
        return [
            'sorting' => [
                'required',
                'string',
                'in:popular,discussed,newest',
            ],
        ];
    }

    public function perform(String $commentableType, Product | Post $commentableModel): LengthAwarePaginator
    {
        return $commentableModel->comments($this->input('sorting'))
            ->with('children')
            ->paginate(10);
    }
}

I have absolutely no idea why the following error is being thrown. I have already tried to google it but found no solution… I am so confused that the correct model is being found and therefore also returned but then the following error is being thrown:

array:5 [ // tests/Feature/Http/CommentController/IndexCommentTest.php:30
  "message" => "Call to undefined method ReflectionUnionType::getName()"
  "exception" => "Error"
  "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/laravel/framework/src/Illuminate/Support/Reflector.php"
  "line" => 151
  "trace" => array:62 [
    0 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/laravel/framework/src/Illuminate/Routing/RouteSignatureParameters.php"
      "line" => 31
      "function" => "isParameterBackedEnumWithStringBackingType"
      "class" => "IlluminateSupportReflector"
      "type" => "::"
    ]
    1 => array:3 [
      "function" => "IlluminateRouting{closure}"
      "class" => "IlluminateRoutingRouteSignatureParameters"
      "type" => "::"
    ]
    2 => array:3 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/laravel/framework/src/Illuminate/Routing/RouteSignatureParameters.php"
      "line" => 31
      "function" => "array_filter"
    ]
    3 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/laravel/framework/src/Illuminate/Routing/Route.php"
      "line" => 533
      "function" => "fromAction"
      "class" => "IlluminateRoutingRouteSignatureParameters"
      "type" => "::"
    ]
    4 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/laravel/framework/src/Illuminate/Routing/ImplicitRouteBinding.php"
      "line" => 80
      "function" => "signatureParameters"
      "class" => "IlluminateRoutingRoute"
      "type" => "->"
    ]
    5 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/laravel/framework/src/Illuminate/Routing/ImplicitRouteBinding.php"
      "line" => 28
      "function" => "resolveBackedEnumsForRoute"
      "class" => "IlluminateRoutingImplicitRouteBinding"
      "type" => "::"
    ]
    6 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/laravel/framework/src/Illuminate/Routing/Router.php"
      "line" => 947
      "function" => "resolveForRoute"
      "class" => "IlluminateRoutingImplicitRouteBinding"
      "type" => "::"
    ]
    7 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php"
      "line" => 41
      "function" => "substituteImplicitBindings"
      "class" => "IlluminateRoutingRouter"
      "type" => "->"
    ]
    8 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php"
      "line" => 180
      "function" => "handle"
      "class" => "IlluminateRoutingMiddlewareSubstituteBindings"
      "type" => "->"
    ]
    9 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php"
      "line" => 126
      "function" => "IlluminatePipeline{closure}"
      "class" => "IlluminatePipelinePipeline"
      "type" => "->"
    ]
    10 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php"
      "line" => 92
      "function" => "handleRequest"
      "class" => "IlluminateRoutingMiddlewareThrottleRequests"
      "type" => "->"
    ]
    11 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php"
      "line" => 54
      "function" => "handleRequestUsingNamedLimiter"
      "class" => "IlluminateRoutingMiddlewareThrottleRequests"
      "type" => "->"
    ]
    12 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php"
      "line" => 180
      "function" => "handle"
      "class" => "IlluminateRoutingMiddlewareThrottleRequests"
      "type" => "->"
    ]
    13 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/app/Http/Middleware/JsonResponse.php"
      "line" => 20
      "function" => "IlluminatePipeline{closure}"
      "class" => "IlluminatePipelinePipeline"
      "type" => "->"
    ]
    14 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php"
      "line" => 180
      "function" => "handle"
      "class" => "AppHttpMiddlewareJsonResponse"
      "type" => "->"
    ]
    15 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php"
      "line" => 116
      "function" => "IlluminatePipeline{closure}"
      "class" => "IlluminatePipelinePipeline"
      "type" => "->"
    ]
    16 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/laravel/framework/src/Illuminate/Routing/Router.php"
      "line" => 797
      "function" => "then"
      "class" => "IlluminatePipelinePipeline"
      "type" => "->"
    ]
    17 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/laravel/framework/src/Illuminate/Routing/Router.php"
      "line" => 776
      "function" => "runRouteWithinStack"
      "class" => "IlluminateRoutingRouter"
      "type" => "->"
    ]
    18 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/laravel/framework/src/Illuminate/Routing/Router.php"
      "line" => 740
      "function" => "runRoute"
      "class" => "IlluminateRoutingRouter"
      "type" => "->"
    ]
    19 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/laravel/framework/src/Illuminate/Routing/Router.php"
      "line" => 729
      "function" => "dispatchToRoute"
      "class" => "IlluminateRoutingRouter"
      "type" => "->"
    ]
    20 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php"
      "line" => 200
      "function" => "dispatch"
      "class" => "IlluminateRoutingRouter"
      "type" => "->"
    ]
    21 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php"
      "line" => 141
      "function" => "IlluminateFoundationHttp{closure}"
      "class" => "IlluminateFoundationHttpKernel"
      "type" => "->"
    ]
    22 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php"
      "line" => 21
      "function" => "IlluminatePipeline{closure}"
      "class" => "IlluminatePipelinePipeline"
      "type" => "->"
    ]
    23 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php"
      "line" => 31
      "function" => "handle"
      "class" => "IlluminateFoundationHttpMiddlewareTransformsRequest"
      "type" => "->"
    ]
    24 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php"
      "line" => 180
      "function" => "handle"
      "class" => "IlluminateFoundationHttpMiddlewareConvertEmptyStringsToNull"
      "type" => "->"
    ]
    25 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php"
      "line" => 21
      "function" => "IlluminatePipeline{closure}"
      "class" => "IlluminatePipelinePipeline"
      "type" => "->"
    ]
    26 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php"
      "line" => 40
      "function" => "handle"
      "class" => "IlluminateFoundationHttpMiddlewareTransformsRequest"
      "type" => "->"
    ]
    27 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php"
      "line" => 180
      "function" => "handle"
      "class" => "IlluminateFoundationHttpMiddlewareTrimStrings"
      "type" => "->"
    ]
    28 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php"
      "line" => 27
      "function" => "IlluminatePipeline{closure}"
      "class" => "IlluminatePipelinePipeline"
      "type" => "->"
    ]
    29 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php"
      "line" => 180
      "function" => "handle"
      "class" => "IlluminateFoundationHttpMiddlewareValidatePostSize"
      "type" => "->"
    ]
    30 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php"
      "line" => 86
      "function" => "IlluminatePipeline{closure}"
      "class" => "IlluminatePipelinePipeline"
      "type" => "->"
    ]
    31 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php"
      "line" => 180
      "function" => "handle"
      "class" => "IlluminateFoundationHttpMiddlewarePreventRequestsDuringMaintenance"
      "type" => "->"
    ]
    32 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/laravel/framework/src/Illuminate/Http/Middleware/HandleCors.php"
      "line" => 62
      "function" => "IlluminatePipeline{closure}"
      "class" => "IlluminatePipelinePipeline"
      "type" => "->"
    ]
    33 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php"
      "line" => 180
      "function" => "handle"
      "class" => "IlluminateHttpMiddlewareHandleCors"
      "type" => "->"
    ]
    34 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/laravel/framework/src/Illuminate/Http/Middleware/TrustProxies.php"
      "line" => 39
      "function" => "IlluminatePipeline{closure}"
      "class" => "IlluminatePipelinePipeline"
      "type" => "->"
    ]
    35 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php"
      "line" => 180
      "function" => "handle"
      "class" => "IlluminateHttpMiddlewareTrustProxies"
      "type" => "->"
    ]
    36 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php"
      "line" => 116
      "function" => "IlluminatePipeline{closure}"
      "class" => "IlluminatePipelinePipeline"
      "type" => "->"
    ]
    37 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php"
      "line" => 175
      "function" => "then"
      "class" => "IlluminatePipelinePipeline"
      "type" => "->"
    ]
    38 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php"
      "line" => 144
      "function" => "sendRequestThroughRouter"
      "class" => "IlluminateFoundationHttpKernel"
      "type" => "->"
    ]
    39 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php"
      "line" => 563
      "function" => "handle"
      "class" => "IlluminateFoundationHttpKernel"
      "type" => "->"
    ]
    40 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php"
      "line" => 324
      "function" => "call"
      "class" => "IlluminateFoundationTestingTestCase"
      "type" => "->"
    ]
    41 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/tests/Feature/Http/CommentController/IndexCommentTest.php"
      "line" => 24
      "function" => "get"
      "class" => "IlluminateFoundationTestingTestCase"
      "type" => "->"
    ]
    42 => array:3 [
      "function" => "TestsFeatureHttpCommentController{closure}"
      "class" => "PTestsFeatureHttpCommentControllerIndexCommentTest"
      "type" => "->"
    ]
    43 => array:3 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/pestphp/pest/src/Factories/TestCaseFactory.php"
      "line" => 151
      "function" => "call_user_func"
    ]
    44 => array:3 [
      "function" => "PestFactories{closure}"
      "class" => "PTestsFeatureHttpCommentControllerIndexCommentTest"
      "type" => "->"
    ]
    45 => array:3 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/pestphp/pest/src/Concerns/Testable.php"
      "line" => 301
      "function" => "call_user_func_array"
    ]
    46 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/pestphp/pest/src/Support/ExceptionTrace.php"
      "line" => 29
      "function" => "PestConcerns{closure}"
      "class" => "PTestsFeatureHttpCommentControllerIndexCommentTest"
      "type" => "->"
    ]
    47 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/pestphp/pest/src/Concerns/Testable.php"
      "line" => 300
      "function" => "ensure"
      "class" => "PestSupportExceptionTrace"
      "type" => "::"
    ]
    48 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/pestphp/pest/src/Concerns/Testable.php"
      "line" => 278
      "function" => "__callClosure"
      "class" => "PTestsFeatureHttpCommentControllerIndexCommentTest"
      "type" => "->"
    ]
    49 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/phpunit/phpunit/src/Framework/TestCase.php"
      "line" => 1608
      "function" => "__test"
      "class" => "PTestsFeatureHttpCommentControllerIndexCommentTest"
      "type" => "->"
    ]
    50 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php"
      "line" => 173
      "function" => "runTest"
      "class" => "PHPUnitFrameworkTestCase"
      "type" => "->"
    ]
    51 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/phpunit/phpunit/src/Framework/TestCase.php"
      "line" => 1214
      "function" => "runTest"
      "class" => "IlluminateFoundationTestingTestCase"
      "type" => "->"
    ]
    52 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/phpunit/phpunit/src/Framework/TestResult.php"
      "line" => 728
      "function" => "runBare"
      "class" => "PHPUnitFrameworkTestCase"
      "type" => "->"
    ]
    53 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/phpunit/phpunit/src/Framework/TestCase.php"
      "line" => 964
      "function" => "run"
      "class" => "PHPUnitFrameworkTestResult"
      "type" => "->"
    ]
    54 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/phpunit/phpunit/src/Framework/TestSuite.php"
      "line" => 684
      "function" => "run"
      "class" => "PHPUnitFrameworkTestCase"
      "type" => "->"
    ]
    55 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/phpunit/phpunit/src/Framework/TestSuite.php"
      "line" => 684
      "function" => "run"
      "class" => "PHPUnitFrameworkTestSuite"
      "type" => "->"
    ]
    56 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/phpunit/phpunit/src/TextUI/TestRunner.php"
      "line" => 653
      "function" => "run"
      "class" => "PHPUnitFrameworkTestSuite"
      "type" => "->"
    ]
    57 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/phpunit/phpunit/src/TextUI/Command.php"
      "line" => 144
      "function" => "run"
      "class" => "PHPUnitTextUITestRunner"
      "type" => "->"
    ]
    58 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/pestphp/pest/src/Console/Command.php"
      "line" => 119
      "function" => "run"
      "class" => "PHPUnitTextUICommand"
      "type" => "->"
    ]
    59 => array:5 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/pestphp/pest/bin/pest"
      "line" => 62
      "function" => "run"
      "class" => "PestConsoleCommand"
      "type" => "->"
    ]
    60 => array:3 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/pestphp/pest/bin/pest"
      "line" => 63
      "function" => "{closure}"
    ]
    61 => array:3 [
      "file" => "/Users/jt/Desktop/Bitbucket/Valet/dbb/vendor/bin/pest"
      "line" => 120
      "function" => "include"
    ]
  ]
]

This is my Pest test function but I get this error also without Pest or without PHPUnit when trying to make a normal API call to this route. Therefore, it has nothing to do with my testing code:

it('displays the first 10 comments for a given commentable model with children', function () {
    $product = Product::factory()->create();

    $comments = Comment::factory()->count(15)->create([
        'commentable_type' => Product::class,
        'commentable_id' => $product->id,
    ]);

    $comments->each(function ($comment) {
        Comment::factory()->count(2)->create([
            'parent_id' => $comment->id,
        ]);
    });

    $response = $this->get(route('comments.index', [
        'commentableType' => 'product',
        'commentableId' => $product->id,
        'sorting' => 'newest',
    ]));

    dd($response->json());
});

I am very thankful for every answer to help me solve this problem!

JS – GET .php file on webserver gives 404

I am trying to load some data from a MySQL database into an HTML website. My approach at the moment is a PHP script that returns the database data as JSON and then a JS script that uses this data for creating the HTML elements.

All is being hosted on a webserver, and currently with all files in the same directory. When running I receive the following error:

GET http://www.<website>.com/fetch_data.php 404 (Not Found)

This is my PHP script:

<?php
// Create a connection to the database
$conn = new mysqli($servername, $username, $password, $dbname);

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

// Construct the SQL query to retrieve player data
$sql = "SELECT * FROM players";

// Execute the SQL query and store the result
$result = $conn->query($sql);

// Check if any rows were returned
if ($result->num_rows > 0) {
  $players = array();
  // Loop through each row and store the player data in an array
  while ($row = $result->fetch_assoc()) {
    $player = array(
      "name" => $row["name"],
      "description" => $row["description"],
      "hcp" => $row["hcp"],
      "image" => $row["image"]
    );
    array_push($players, $player);
  }
  // Encode the array as JSON and return it
  header('Content-Type: application/json');
  echo json_encode($players);
} else {
  echo "No players found";
}

// Close the database connection
$conn->close();
?>

And this is my JS script that I include in my HTML:

// Container reference
const gridContainer = document.querySelector(".grid-container");

// Fetch the data from the database
const xhr = new XMLHttpRequest();
xhr.open("GET", "./fetch_data.php");
xhr.onload = function() {
  if (xhr.status === 200) {
    const data = JSON.parse(xhr.responseText);
    // Loop through the data and create a grid item for each player
    data.forEach(player => {
      const gridItem = document.createElement("div");
      gridItem.classList.add("grid-item");
      gridItem.innerHTML = `
        <div class="top-wrapper">
          <div class="img-wrapper">
            <img src="pics/${player.image}" alt="${player.name}">
          </div>
          <div class="info-wrapper">
            <h2>${player.name}</h2>
            <p>${player.description}</p>
          </div>
        </div>
        <div class="stats-wrapper">
          <div class="stats-item">
            <h3>HCP</h3>
            <p>#${player.hcp}</p>
          </div>
        </div>
        <div class="input-wrapper">
          <input type="text" placeholder="???"/>
          <button class="input-btn"><i class="fa-solid fa-paper-plane"></i></button>
        </div>
      `;
      gridContainer.appendChild(gridItem);
    });
  } else {
    console.error(xhr.statusText);
  }
};
xhr.send();

Any help is appreciated – feel free to give input on my approach as well.

How is it possible to stop at the first failure when using dataProvider? ( phpUnit )

I created a data provider for a test case. It provides smaller and then longer arrays as an input for the test function. I would like to stop at the first error, because the error message gets harder to understand for larger inputs. But I would like to test for large inputs as well.

function testFunction(array $inputOne, array $inputTwo) {...}

function myDataProvider() {
    return [
        [[1,2], [3,4]],
        [[1,2,3,4,5,6,7,8,9], [3,4,5,6,7,7,8,9,10]],
        [<<LARGE ARRAY>>, <<LARGE ARRAY>>],
    ];
}