I created a form for a username and a text message but right now pressing submit doesn't actually submit anything despite it being close to the code for my login and registration form wich do properly work. the code:
<form id="myChatForm">
<input type= "text" placeholder= "Enter a name" name= "user_name" id= "user_name"><br>
<textarea placeholder= "type your message" name="message" id="message" cols="30" rows="3"></textarea><br>
<button type= "submit" name= "submit" value= "submit" class= "btn btn-succes btn-lg" id = "sendMessageBtn"> Send Message</button><br>
</form>
<?php
include("config.php");
if (isset($_POST['user_name']) && isset($_POST['message'])){
if (isset($_POST['user_name'])) {
$uname = ($_POST['user_name']);
}
if (isset($_POST['message'])) {
$umessage = ($_POST['message']);
}
$query = "INSERT INTO chatroom (name, message) VALUES ('$uname', '$umessage')";
$run = mysqli_query($con, $query);
}
?>
For as far as I know, the problem lies with the form because before I had
if (isset($_POST['user_name']) && isset($_POST['message'])){
I would get errors saying that user_name and message were both undifined.