Javascript php代码在调用函数之前正在运行。(加载页面时,启动整个php代码)

Javascript php代码在调用函数之前正在运行。(加载页面时,启动整个php代码),javascript,php,jquery,web,Javascript,Php,Jquery,Web,这是我的密码。。PHP代码在单击按钮之前运行 $(document).click(function(){ $('input[type="button"]').click(function(){ <?php include "posts/connections/db_connect.php"; mysql_query("insert into post_tags(post_id,user_id) values(3,2)");

这是我的密码。。PHP代码在单击按钮之前运行

$(document).click(function(){
    $('input[type="button"]').click(function(){
        <?php 
        include "posts/connections/db_connect.php";
        mysql_query("insert into post_tags(post_id,user_id) values(3,2)");
        ?>
    });
});

</script>
<input type="button" value="submit" />

HTML元素是

是的,php是在服务器端运行的,那么问题是什么?您是否试图在不刷新页面的情况下提交表单?如果是这样的话,您需要使用ajax将数据发送到php文件,并且在那里您需要放置php查询并包含数据库连接?php不能在javascript中执行。因为javascript在浏览器上运行,PHP在服务器上运行。如果您愿意,可以进行ajax调用。是否要在单击“是”按钮后执行。我想在单击按钮后执行查询。
$(document).click(function(){
    $('input[type="button"]').click(function(){
        <?php 
        include "posts/connections/db_connect.php";
        mysql_query("insert into post_tags(post_id,user_id) values(3,2)");
        ?>
    });
});

</script>
<input type="button" value="submit" />