[英]How exactly do I make a button start a database (sql) query in php?
I'm trying to create a feedback page on this website I'm coding and I need my submit button to start a query so that the message is sent and stored in a feedback table in my database. 我正尝试在正在编码的网站上创建一个反馈页面,并且需要我的“提交”按钮来启动查询,以便将消息发送并存储在数据库的反馈表中。
But I can't seem to be able to find the reason my implementation does not work. 但是我似乎无法找到我的实现无法正常工作的原因。 I think it worked this way the last time, any help would be appreciated. 我认为上次以这种方式工作,将不胜感激。
<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>";
}
}
?>
Buttons with the type submit, are intended to submit forms. 类型为Submit的按钮用于提交表单。 Your markup doesn't have any <form> </form>
tags at all. 您的标记根本没有任何<form> </form>
标记。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.