script not found or unable to stat

Problems with the Windows version of XAMPP, questions, comments, and anything related.

script not found or unable to stat

Postby Didiech » 02. March 2023 15:30

Hi all,
I am new in web programming and while trying to build a contact form using PHP and AJAX, I got an issue that I couldn't get rid of. I have been googling for hours and stil the same issue.
I have in my root folder "mySite" my index.html file that contains the contact form (mySite/index.html)
I have a contact.php file located in a php subfolder (mySite/php/contact.php)
And I have a contact.js file located in a js subfolder (mySite/js/contact.js)
My issue is that xampp always try to get access to a file called index.php and try to locate it in "mySite/php/index.php"
I have tried to modify the DirectoryIndex to set it to "DirectoryIndex index.html" and after that to set the <ifModul...> part to just DirectoryIndex index.html. I also tried to add my data in <VirtulaHost ...> part in httpd-vhosts.conf file.
Before that I have tried to set in my index.html form action="/php/contact.php", include('../index.html') in my php file and add url: "../php/contact.php" in my js file...
Nothing worked so far... :cry:
I f anyone can help me on this it will be kind :mrgreen:
Thanks in advanced
Didiech
Didiech
 
Posts: 5
Joined: 02. March 2023 15:08
XAMPP version: v3.3.0
Operating System: Win10

Re: script not found or unable to stat

Postby Froosh » 02. March 2023 18:12

Not sure this is XAMPP configuration specific, but rather related to Apache and PHP, which are just packages used by XAMPP.

In my experience, getting things configured properly can be tricky. I would be sure that in any experimenting I've done in the past, I make sure that I undo, or unravel changes that did not pan out. Otherwise, it can lead to you traveling down wrong paths. My best advice would be to try getting things working without placing bits in separate folders. Then, once that is working, start fiddling with the structure. That's what has worked best for me.

Do you know what script is referred to when you indicate "script not found or unable to stat?"

Where is that message coming from?

Is there anything in the Apache or PHP log that could provide you with more clues?

If I were trying to troubleshoot a site I'm developing, those are the sorts of things I'd start with, which perhaps you have done....
User avatar
Froosh
 
Posts: 138
Joined: 27. March 2022 17:56
XAMPP version: 8.2.0
Operating System: Windows 11 Pro

Re: script not found or unable to stat

Postby Nobbie » 02. March 2023 20:39

Please show us the full source code of all files.
Nobbie
 
Posts: 13176
Joined: 09. March 2008 13:04

Re: script not found or unable to stat

Postby Didiech » 04. March 2023 09:38

Hi Guys,
Thanks for answering me... Sorry, I have been absent for personnal reasons... :cry:

Here is the code I have "now" for each part

File placed in root and named "index.html" :
Code: Select all
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>ab-DevWeb</title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
        <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
        <link href="https://fonts.googleapis.com/css2?family=Orbitron&display=swap" rel="stylesheet">
        <link href="https://fonts.googleapis.com/css2?family=Montserrat+Alternates:ital,wght@0,300;0,400;0,500;0,600;1,400;1,500;1,600" rel="stylesheet">
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.3/font/bootstrap-icons.css">
        <link href="css/main.css" rel="stylesheet" type="text/css"/>
        <script src="js/core.js" type="text/javascript"></script>
        <script src="js/scroll.core.js" type="text/javascript"></script>
        <script src="js/scroll.scrolldown.js" type="text/javascript"></script>
        <script src="js/contact.js" type="text/javascript"></script>
        <script src="js/navbar.js" type="text/javascript"></script>
    </head>

    <body id="top" data-bs-spy="scroll" data-bs-target="myNavbar">

        <section id="contact">
            <div class="container">
                <div class="separator"></div>
                <div class="heading">
                    <h2>Contact</h2>
                </div>
                <div class="row justify-content-center">
                    <div class="col-lg-12 col-md-12">
                        <div class="wrapper">
                            <div class="row no-gutters">                               
                                <div class="col-xl-5 d-flex align-items-stretch">
                                    <div class="info-wrap w-100 p-lg-5 p-4">
                                        <div class="question-pic-bg" style="position: relative";></div>
                                    </div>
                                </div>                               
                               
                                <div class="col-xl-7 d-flex align-items-stretch">
                                    <div class="contact-wrap w-100 p-md-5 p-4">
                                        <h3 class="mb-4">Contactez-moi</h3>
                                        <div id="form-message-warning" class="mb-4"></div>
                                        <div id="form-message-success" class="mb-4"></div>
                                        <form id="contact-form" method="post" action="" role="form">
                                            <div class="row">
                                                <div class="col-md-6">
                                                    <label for="firstname">Prénom <span class="require-marker">*</span></label>
                                                    <input id="firstname" type="text" name="firstname" required class="form-control" placeholder="Votre prénom">
                                                    <p class="comments"></p>
                                                </div>
                                                <div class="col-md-6">
                                                    <label for="name">Nom <span class="require-marker">*</span></label>
                                                    <input id="name" type="text" name="name" required class="form-control" placeholder="Votre Nom">
                                                    <p class="comments"></p>
                                                </div>
                                                <div class="col-md-6">
                                                    <label for="email">Email <span class="require-marker">*</span></label>
                                                    <input id="email" type="email" name="email" required class="form-control" placeholder="Votre Email">
                                                    <p class="comments"></p>
                                                </div>
                                                <div class="col-md-6">
                                                    <label for="phone">Téléphone</label>
                                                    <input id="phone" type="tel" name="phone" class="form-control" placeholder="Votre Téléphone">
                                                    <p class="comments"></p>
                                                </div>
                                                <div class="col-md-12">
                                                    <label for="message">Message <span class="require-marker">*</span></label>
                                                    <textarea id="message" name="message" required class="form-control" placeholder="Votre Message" rows="4"></textarea>
                                                    <p class="comments"></p>
                                                </div>
                                                <div class="col-md-12">
                                                    <p class="blue"><strong>* Ces informations sont requises.</strong></p>
                                                </div>
                                                <div class="col-md-12">
                                                    <input type="submit" name="SubmitButton" class="btn" value="Envoyer">
                                                </div>   
                                            </div>
                                        </form>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

    </body>
</html>


Now the file placed in the "root/php/" folder and named "contact.php" :

Code: Select all
<?php

    $array = array("firstname" => "", "name" => "", "email" => "", "phone" => "", "message" => "",
    "firstnameError" => "", "nameError" => "", "emailError" => "", "phoneError" => "", "messageError" => "",
    "isOkToSend" => false, "hasError" => false);
    $sendTo = "xxx@xxx.com";

    if (isset($_POST['SubmitButton']))
    {
       
        $array["firstname"] = checkInput($_POST["firstname"]);
        $array["name"] = checkInput($_POST["name"]);
        $array["email"] = checkInput($_POST["email"]);
        $array["phone"] = checkInput($_POST["phone"]);
        $array["message"] = checkInput($_POST["message"]);
        $array["isOkToSend"] = true;
        $array["hasError"] = false;
        $emailText = "";

        if (empty($array["firstname"]))
        {
            $array["firstnameError"] = "Vous devez saisir votre prénom !";
            $array["isOkToSend"] = false;
            $array["hasError"] = true;
        }
        else
        {
            $emailText .= "Firstname : {$array["firstname"]}\n";
        }

        if (empty($array["name"]))
        {
            $array["nameError"] = "Vous devez saisir votre nom !";
            $array["isOkToSend"] = false;
            $array["hasError"] = true;
        }
        else
        {
            $emailText .= "Name : {$array["name"]}\n";
        }

        if (!isEmail($array["email"]))
        {
            $array["emailError"] = "L'email n'est pas valide !";
            $array["isOkToSend"] = false;
            $array["hasError"] = true;
        }
        else
        {
            $emailText .= "E-mail : {$array["email"]}\n";
        }

        if (!isPhone($array["phone"]))
        {
            $array["phoneError"] = "Le numéro n'est pas valide !";
            $array["isOkToSend"] = false;
            $array["hasError"] = true;
        }
        else
        {
            if (!empty($phone)) $emailText .= "Phone : {$array["phone"]}\n";
        }

        if (empty($array["message"]))
        {
            $array["messageError"] = "Vous devez saisir un message !";
            $array["isOkToSend"] = false;
            $array["hasError"] = true;
        }
        else
        {
            $emailText .= "Message : {$array["message"]}";
        }

        if ($array["isOkToSend"])
        {
            $headers = "From : {$array["firstname"]} {$array["name"]} <{$array["email"]}>\r\nReply-To : {$array["email"]}";
            mail($sendTo, "Contact from ab-Devweb WebSite !", $emailText, $headers);
        }

        echo json_encode($array);

    }

    function checkInput ($var)
    {
        $var = trim($var);
        $var = stripslashes($var);
        $var = htmlspecialchars($var);
        return $var;
    }
   
    function isEmail($var)
    {
        return filter_var($var, FILTER_VALIDATE_EMAIL);
    }

    function isPhone($var)
    {
        return preg_match("/^[0-9 +]*$/", $var);
    }
?>


And finally the file placed in "root/js/" folder and named "contact.js" :

Code: Select all
$(function () {
   
    $('#contact-form').submit(function(e) {
        e.preventDefault();
        $('.comments').empty();
        $('.warning-comments').empty();
        $('.sent-comments').empty();
        var postdata = $('#contact-form').serialize();
       
        $.ajax({
            type: 'POST',
            url: 'php/contact.php',
            data: postdata,
            dataType: 'json',
            success: function(json) {
                 
                if(json.isOkToSend)
                {
                    $('#form-message-success').append("<p class='sent-comments'>Votre message a bien été envoyé. Merci de m'avoir contacté !</p>");
                    $('#contact-form')[0].reset();
                }
                else
                {
                    $('#form-message-warning').append("<p class='warning-comments'>Il y a des erreurs dans votre saisie !</p>");
                    $('#firstname + .comments').html(json.firstnameError);
                    $('#name + .comments').html(json.nameError);
                    $('#email + .comments').html(json.emailError);
                    $('#phone + .comments').html(json.phoneError);
                    $('#message + .comments').html(json.messageError);
                }               
            }
        });
    });

})


Hop that will help
Didiech
 
Posts: 5
Joined: 02. March 2023 15:08
XAMPP version: v3.3.0
Operating System: Win10

Re: script not found or unable to stat

Postby Didiech » 04. March 2023 09:45

@Froosh,

I have done the job doing it all in the same code and it was working well. It is when I have made it in differents files that the problem occured. About the error log, I don't know about the script that it is refering too... Truth is that it is my first website ever, so I am not quite aware of all the terms and even less of where to get the right infos... :cry:

Sorry about that :cry:
Didiech
 
Posts: 5
Joined: 02. March 2023 15:08
XAMPP version: v3.3.0
Operating System: Win10

Re: script not found or unable to stat

Postby Didiech » 04. March 2023 10:03

Code: Select all
[Sat Mar 04 09:59:34.907570 2023] [ssl:warn] [pid 10656:tid 408] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Sat Mar 04 09:59:34.948518 2023] [core:warn] [pid 10656:tid 408] AH00098: pid file C:/xampp/apache/logs/httpd.pid overwritten -- Unclean shutdown of previous Apache run?
[Sat Mar 04 09:59:34.951030 2023] [ssl:warn] [pid 10656:tid 408] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Sat Mar 04 09:59:34.997951 2023] [mpm_winnt:notice] [pid 10656:tid 408] AH00455: Apache/2.4.54 (Win64) OpenSSL/1.1.1p PHP/8.2.0 configured -- resuming normal operations
[Sat Mar 04 09:59:34.997951 2023] [mpm_winnt:notice] [pid 10656:tid 408] AH00456: Apache Lounge VS16 Server built: Jun 22 2022 09:58:15
[Sat Mar 04 09:59:34.997951 2023] [core:notice] [pid 10656:tid 408] AH00094: Command line: 'c:\\xampp\\apache\\bin\\httpd.exe -d C:/xampp/apache'
[Sat Mar 04 09:59:35.006649 2023] [mpm_winnt:notice] [pid 10656:tid 408] AH00418: Parent: Created child process 11784
[Sat Mar 04 09:59:35.392605 2023] [ssl:warn] [pid 11784:tid 412] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Sat Mar 04 09:59:35.430030 2023] [ssl:warn] [pid 11784:tid 412] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Sat Mar 04 09:59:35.495666 2023] [mpm_winnt:notice] [pid 11784:tid 412] AH00354: Child: Starting 150 worker threads.


This is what I get while starting Xampp in my file error.log
And when I try to submit my contact form, nothing happened anymore... It is like it cannot reach the contact.php an or the contact.js files. :cry:
Didiech
 
Posts: 5
Joined: 02. March 2023 15:08
XAMPP version: v3.3.0
Operating System: Win10

Re: script not found or unable to stat

Postby Nobbie » 04. March 2023 11:50

You have an empty action Tag in your form:

Code: Select all
<form id="contact-form" method="post" action="" role="form">


How will the Browser know that you want to start contact.php?
Nobbie
 
Posts: 13176
Joined: 09. March 2008 13:04

Re: script not found or unable to stat

Postby Nobbie » 04. March 2023 12:06

Didiech wrote:@Truth is that it is my first website ever, so I am not quite aware of all the terms and even less of where to get the right infos... :cry:


That is your first website? Why do you start with such a horrible JavaScript / PHP / HTML Mixture without having the slightest clue of what you are doing there? Its like a new driver immediately starts with a formula 1 car...

You really should begin with simple HTML, then add some simple FORMS, than add some simple PHP Scrtips and try to learn and understand, how things are working together. Later on, when you are a real professional, you may add some JavaScript and finally (in a few years) try to integrate AJAX, But not the other way round, you cannot start with a hyper sophisticated framework without knowing anything of what you are doing there. Programmiing is more than copy and paste some code, which you dont understand.

That index.html is a pain.
Nobbie
 
Posts: 13176
Joined: 09. March 2008 13:04

Re: script not found or unable to stat

Postby Froosh » 04. March 2023 15:40

There is nothing in the log you shared that indicates an issue with XAMPP/Apache. You could look in the PHP log for your site, to see if there are any PHP errors specifically related to your site.

Personally, code indentation helps show intended structure. As Nobbie points out, why start your first project with such a mix? It truly is a big learning curve to start with, and to introduce so much complexity right from the start?

I've done development for decades, and had worked with JavaScript early on in its life. Stepped away from heavy web development for a few years and when I started trying to work on a client-side web interface using JavaScript, I was amazed, and a bit daunted with the complexity at first. I can only imagine if I had little to no experience what I would have thought.

Was your code base modified, other than paths to files, when you decided to restructure it? You say it worked when it was in one folder, but does worked mean based on what you have included above? To me that seems a bit unlikely.

Anyhow, there are quite a few script bits being pulled in from the HTML page, and really this forum is more about XAMPP and not how to create a web site, let alone how to learn to create one. There are quite a few resources, okay many, on how to create web sites. You would be better served starting simple, learning, and gaining proficiency, rather than jumping into the deep end of the pool, as I feel you have done.
User avatar
Froosh
 
Posts: 138
Joined: 27. March 2022 17:56
XAMPP version: 8.2.0
Operating System: Windows 11 Pro

Re: script not found or unable to stat

Postby Froosh » 04. March 2023 18:58

For the fun of things, or more likely because I was bored, and curious about what the supplied markup and code would actually look like, and do, I did some messing around.

I took the bits provided and placed them in the file/folder structure indicated. The HTML Header section has errors, and there are other HTML syntax errors. If I just correct the header syntax, while I get a "form", it is filled with HTML bits, and renders poorly due to additional errors in the HTML syntax. Quite a mess, and I find it hard to believe that this was a working application...

Locally, I corrected the HTML, and did get a form to render. The form submit is handled in your JavaScript using jQuery, and the AJAX. It does ultimately call contact.php to process the form input. However, your form data, as submitted does not contain a
Code: Select all
$_POST['SubmitButton']
value, so
Code: Select all
isset($_POST['SubmitButton'])
in contact.php evaluates to false, and none of the code in the block executes. I simply added an appropriate "else" block to the code that logged a message. Error handling in your JavaScript, and PHP code, or any code for that matter is important, and a valuable asset in figuring out what is, or in your case is not, happening.

Here's a dump of the $_POST data: Array\n(\n [firstname] => asdfa\n [name] => asdfa\n [email] => ajdferg@gmail.com\n [phone] => 8457818793\n [message] => hjfhgfghfgh\n)\n

If I change the test to
Code: Select all
$_POST['firstname']
the code would flow to the mail(...) function call later in the block.

I used VSCode to view and format the code, XAMPP to host the site on my system, and Edge to view the site.

Good luck with your adventure.
User avatar
Froosh
 
Posts: 138
Joined: 27. March 2022 17:56
XAMPP version: 8.2.0
Operating System: Windows 11 Pro

Re: script not found or unable to stat

Postby Didiech » 05. March 2023 14:34

Hi guys,
Thank you for all your answers... :D
@Nobbie - Yes, I know that I have to start with little projects to learn how to correctly code and understand how everything works but I have many ideas and want to make them "real" ASAP. :wink:
@Froosh - Sorry for the code, in VS Code everything is indented but as I haven't paste it with the Code tag, everything went totally messy... Thanks for your time trying to understand everything and thanks to you I managed to correct my code throught the "isset" part and now everything is working perfectly.
Once more, thanks a lot guys :)

[EDIT by Altrea: I have added Code Tags around your code sections. Hope that helps]
Didiech
 
Posts: 5
Joined: 02. March 2023 15:08
XAMPP version: v3.3.0
Operating System: Win10


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 155 guests