1

Пытаюсь отправить простую форму на MongoDB. Есть страница "log_in_page.html", "index.php". Каждый раз делая submit, получаю error 500. В интернете нашлось несколько вариантов, все были применены, но проблему это не решило. А именно:

Форма:

<form method='POST' action='index.php'>
 <input type="email" name="email">Email</input>
 <input type="password" name="password">Password</input>
 <button type="submit">Submit</button>
</form>

Файл php (далее user - это БД и user_data - это коллекция):

<?php
$client = new MongoDB\Client(
    'mongodb+srv://user_access:мой_пароль@кластер.mjvzyla.mongodb.net/? 
     retryWrites=true&w=majority'
);
$userCollection = $client->user->user_data;
$insertOneResult = $userCollection->insertOne([
   'email' => $_POST['email'],
   'password' => $_POST['password'],
]);
?>

Далее ошибка Internal Server Error.

1 Answers1

0

Порылась в логах, была ошибка с сертификатами: TLS handshake failed: certificate verify failed (20): unable to get local issuer certificate calling hello on...

Решение - добавить &tlsAllowInvalidCertificates=true

$client = new MongoDB\Client(
    'mongodb+srv://user_access:мой_пароль@кластер.mjvzyla.mongodb.net/? 
     retryWrites=true&w=majority&tlsAllowInvalidCertificates=true'
);