Click here to Skip to main content
15,912,977 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am facing path issue

Warning: require_once(../DB/DBConnect.php): Failed to open stream: No such file or directory in C:\xampp\htdocs\ShivLMSNew\API\insertUser.php on line 3

Fatal error: Uncaught Error: Failed opening required '../DB/DBConnect.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\ShivLMSNew\API\insertUser.php:3 Stack trace: #0 C:\xampp\htdocs\ShivLMSNew\signup.php(5): include_once() #1 {main} thrown in C:\xampp\htdocs\ShivLMSNew\API\insertUser.php on line 3


Screenshot of project directory
Screenshot of directory - Album on Imgur[^]

What I have tried:

<?php

require_once '../DB/DBConnect.php';
$db=new DBConnect();
$pdoObj=$db->connectToDB();

$response=array();

if($_POST['radioUserType'] AND $_POST['txtUserName'] AND $_POST['txtEmail'] AND $_POST['txtMobile'] AND $_POST['txtPassword1'] AND $_POST['txtPassword2'])
{
    include_once ('../Classes/SanitizerClass.php');
   
    $userType = $_POST['radioUserType'];
    $userName =SanitizerClass::sanitizeUsername($_POST['txtUserName']);
    $email = SanitizerClass::sanitizeEmail($_POST['txtEmail']);
    $mobile=trim($_POST['txtMobile']);
    $plain_password=$_POST['txtPassword1'];
    $encrypted_password = password_hash($plain_password,PASSWORD_BCRYPT);
    $pwd2=$_POST['txtPassword2'];
    $isEmailVerified="NotVerified";
    $generated_activationCode = md5(uniqid(rand()).time());
    $dateRegistered=date('d-m-Y');
    $ip=crud::getVisitorIP();

    include_once '../inc/crud.php';
    list($CountryName,$CityName,$ContinentName,$CurrencySymbol,$CurrencyCode,$TimeZone)=CRUD::getVisitorsDetails($ip);//here 47.9.193.174 should be changed to $ip

    
    include_once '../Classes/User.php';  
    $user=new User();

    $isEmailAlreadyTakenBySomeone= $user->isEmailAlreadyTakenBySomeone($email);
    if($isEmailAlreadyTakenBySomeone==true)
    {
        $response['error'] = true;
        $response['message'] = "Registration failed. Someone has already registered with the same email.";
    }
    else
    {
        $isEmailHasValidFormat = $user->isEmailHasValidFormat($email);
        if($isEmailHasValidFormat==true)
        {
            $stmt = $conn->prepare("INSERT INTO tbl_users(userType,userName,email,mobile,password,isEmailVerified,activationCode,dateRegistered,ipAddress,countryName,cityName,continent,currencySymbol,currencyCode,timeZone) 
            VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
            $stmt->bind_param("sssssssssssssss",$userType,$userName,$email,$mobile,$encrypted_password,$isEmailVerified,$generated_activationCode,$dateRegistered,$ip,$CountryName,$CityName,$ContinentName,$CurrencySymbol,$CurrencyCode,$TimeZone);
            if($stmt->execute() == TRUE)
            {
                $response['error'] = false;
                $response['message'] = "User registered successfully!";
            } 
            else
            {
                $response['error'] = true;
                $response['message'] = "failed\n ".$conn->error;
            }
        }
        else
        {
            $response['error'] = true;
            $response['message'] = "Error in registering. Invalid Email Format.";
        }

    }
} 
else
{
    $response['error'] = true;
    $response['message'] = "All fields are not filled";
}
echo json_encode($response);
Posted
Updated 20-Jun-21 4:04am
v2

1 solution

What you are showing looks like it should work. However the error message contains the following: "(include_path='C:\xampp\php\PEAR')". I cannot be certain, but that could mean that it is looking in "C:\xampp\php\PEAR\..\DB\ ...". Try putting the full absolute path in your include statement and see what happens.

See also PHP: Description of core php.ini directives - Manual[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900