0
Very good evening I’m developing a chat (for study) and I made a form to send the messages as I always do but the php file does not load on the local server of the http 500 error that usually occurs when there is an error in the file but I have already tested in cmd and found nothing
if anyone can help I appreciate
index php.
<form method="post" action="php/insert.php">
<div class="input-group mb-3">
<input type="text" name="mensagem" class="form-control" placeholder="Sua mensagem" aria-label="Recipient's username" aria-describedby="basic-addon2">
<div class="input-group-append">
<button class="btn btn-secondary" type="submit">Enviar</button>
</div>
</div>
</form>
Insert.php
<?php
session_start();
include("connect.php");
$id = isset($_SESSION['id']) ? $_SESSION['id'] : '';
$nome = isset($_SESSION['name']) ? $_SESSION['name'] : '';
if(!empty($id) && !empty($nome) && !empty($_POST["mensagem"])){
$sql = $pdo->prepare("INSERT INTO conversas (mensagem, id, nome) VALUES (':mensagem', ':id', ':nome')");
$sql->bindValue(":mensagem", $_POST["mensagem"]);
$sql->bindValue(":id",$id);
$sql->bindValue(":nome", $nome);
$sql->execute();
header('location: ../index.php');
}else {
$_SESSION['mensagem-not'] = 'É preciso escrever a mensagem';
header('location: ../index.php');
}
?>
connect.php
<?php
$usr = "root";
$pwd = "j21042005J$";
try {
$pdo = new PDO('mysql:host=localhost;dbname=chatsimples', $usr, $pwd);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
?>
Opa thank you very much I tested here and it worked
– Joaovitor-sr