我正尝试在我正在编写代码的网站上创建一个反馈页面,我需要提交按钮来启动查询,以便发送消息并将其存储在我数据库的反馈表中。
但我似乎无法找到我的实现不起作用的原因。我认为上次它是这样工作的,我们将不胜感激。
<div class="form-group">
<label for="msgType">What is your concern?</label>
<select name="msgType" method="post" class="form-control input-lg" id="msgType">
<option value="1">I wish to report incorrect information cited on the website.</option>
<option value="2">I wish to report the existence of another bistro.</option>
<option value="3">I wish to thank the admin personally.</option>
<option value="4">I wish to express some other concern.</option>
</select>
</div>
<div class="form-group">
<label for="message">Your message:</label>
<textarea class="form-control" method="post" rows="15" id="message" name="message" placeholder="Thou, dear customer, may express Your concern here in any extent or form your majesty finds appropriate."></textarea>
</div>
<button type="submit" class="btn btn-info">Send</button>
<input type="hidden" name="submitted_feedback" value="1">
</div>
</section>
</div>
</div>
</section>
</body>
</html>
<!-- QUERY SECTION -->
<?php
if(isset($_POST['submitted_feedback']) == 1)
{
$message = mysqli_real_escape_string($dbc, $_POST['message']);
$q = "INSERT INTO feedback(type, message) VALUES ($_POST[msgType], '$message')";
$r = mysqli_query($dbc, $q);
echo 'dis is running';
if($r)
{
echo "<script type='text/javascript'>alert('Your message was sent! :)');</script>";
}
}
?>
最佳答案
提交类型的按钮用于提交表单。您的标记没有任何 <form> </form>
根本没有标签。
关于php - 如何让按钮在 php 中启动数据库 (sql) 查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49310954/