Ich habe ein Problem mit einfacher PHP Form bekommt:PHP Methode POST funktioniert nicht
<form class="form-horizontal" method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>" align="center">
<?php
session_start();
if (isset($_SESSION['login'])) {
echo'<div class="row">';
echo '<textarea style="resize: none; width: 45%; height: 150px;" name="comments" id="comments" placeholder="Leave a comment here..."></textarea>';
echo '</div>';
echo '<div class="row" style="margin-top: 10px;">';
echo '<button type="button" class="btn btn-success" name="complete">Submit</button>';
echo '</div>';
} else {
echo '<h4>You must be logged in to add comments.</h4>';
}
?>
</form>
Und PHP Anfrage:
<?php
if (isset($_POST['complete'])) {
$text_field = $_POST['comments'];
$result = mysqli_query($link, "INSERT INTO `comments` (`text`) VALUES ('$text_field')");
}
?>
Wenn ich auf Schaltfläche nichts passiert.
Da Ihre Schaltfläche den Typ 'button' hat passiert nichts, entweder entfernen Sie das Attribut oder ändern Sie es in' submit' – Dale
Wenn Sie 'type =" button "' verwenden möchten, müssen Sie JS das Formular senden. Ansonsten ändere es per @ Aloks Antwort. –