php - 如何让按钮在 php 中启动数据库 (sql) 查询?

标签 php html mysql button

我正尝试在我正在编写代码的网站上创建一个反馈页面,我需要提交按钮来启动查询,以便发送消息并将其存储在我数据库的反馈表中。

但我似乎无法找到我的实现不起作用的原因。我认为上次它是这样工作的,我们将不胜感激。

                       <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>根本没有标签。

Here you go

关于php - 如何让按钮在 php 中启动数据库 (sql) 查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49310954/

相关文章:

javascript - PHP json_encode 作为数组字符串返回,但未正确转换为 JavaScript 中的数组

php - 在 Yii CDbCriteria 语句中使用 CASE

MYSQL 查询 - 一些结果不返回

MySQL - 你能检索列的默认值吗?

javascript - 使用 Node JS 将数据从 Excel 导入 MySql

php - 搜索多列 mysql 和 php

javascript - 从服务器获取刷新数据

javascript/jQuery : Adding linebreak in title -- works in IE9, 但 IE8 中没有

javascript - 更新同一页面内的 php 变量而无需重新加载页面

javascript - 获取 html 元素作为字符串