问题
Same code works for normal form but not for modal form. Cannot understand why.
Below is one of the modals that I am using in my admin dashboard. Currently it has only one field in the form. But when I try to submit the form, the modal closes but data is not inserted into database and also it is not displaying any error. Following is the code for Modal and Form.
<li><a href="#modal1" class="tooltipped modal-trigger" data-position="bottom" data-delay="50" data-tooltip="Update Events"><i class="material-icons">announcement</i></a></li>
<div id="modal1" class="modal">
<div class="modal-content ">
<div class="row">
<form class="col s12" action="updatetext.php" method="POST">
<div class="row">
<div class="input-field col s12">
<!-- <i class="material-icons prefix">mode_edit</i> -->
<textarea id="icon_prefix2" class="materialize-textarea" style="color:#000"></textarea>
<label for="icon_prefix2" >News</label>
<input type="text" name="news">
</div>
</div>
<input type="submit" value="submit" class="modal-action modal-close waves-effect waves-green btn-flat ">
<a name="submit" class="modal-action modal-close waves-effect waves-green btn-flat ">Update</a>
<a class="modal-action modal-close waves-effect waves-green btn-flat ">Cancel</a>
</div>
</form>
</div>
</div>
This is the code for updatetext.php
<?php
include_once("db.php");
error_reporting(E_ALL);
ini_set('display_errors', 1);
if(isset($_POST["submit"])) {
$news = $_POST['news'];
$news = mysqli_real_escape_string($conn, $news);
$query = mysqli_query($conn, "INSERT INTO news (newsmatter) VALUES ('$news')");
}
?>
来源:https://stackoverflow.com/questions/37811287/unable-to-insert-data-into-mysql-from-a-materialized-modal-form