嗯,试试这个:我使用 Jquery 将按钮类传递给 Ajax 请求,该请求转到下面的 php 文件。
编辑:确保您正确解析和过滤数据以防止注入攻击。这只是表明您可以将 html 类传递给 PHP。
文件
<html>
<head>
<script type="text/javascript">
// Assign your button an on click event using jquery
$('#button-id').click(function(){
//Store our current elements class value
var buttonclass = $(this).attr("class");
//Create an ajax request that goes to aphp file and will receive your class value
$.ajax({
url: 'ajaxfile.php?buttonclass='+buttonclass,
success:function(data){
alert(data);
}
});
});
</script>
</head>
<body>
<input id="button-id" class="button-1" type="button" />
</body>
</html>
PHP文件
<?php
$pdo = new PDO("mysql:dbname=newdbnaem;host=1.1.1.1:1111", "owner", "passwordlulz");
$buttonclass = $_GET['buttonclass'];
$query = $pdo->prepare("SELECT * FROM table WHERE name = :name");
$query->execute(array(':name' => $buttonclass));
?>
Success
<?php exit(0);
?>
希望这会有所帮助!