我正在使用ajax& amp; PHP。当用户点击时,“明星”不仅会出现问题。需要发送值,但也要评估项目的标识符。我怎么送两个?我正在尝试回复id#。与此同时,我尝试使用PHP实时显示SQL表中的当前评级。我应该这样做吗?
带有单选按钮的表格
<div class="rating">
<form name="star" class="rating" method="post" action="getStarno(this.value, <?php echo $id; ?>)"
<legend><?php if(is_null($avgrate)){echo "Rate me!";} else {echo round($avgrate, 2);} ?> / 3</legend>
<fieldset>
<input type="radio" name="Starno" value="1" onclick="this.form.submit()"/>
<input type="radio" name="Starno" value="2" onclick="this.form.submit()"/>
<input type="radio" name="Starno" value="3" onclick="this.form.submit()"/>
</fieldset>
</form>
</div>
JS
function getStarno(int, $id)
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("rating").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","../rating.php?Starno="+int,true);
xmlhttp.send();
}
PHP
<?php
isset($_GET['id']);
isset($_GET['starno']);
$con=mysqli_connect ("","","","");
mysqli_query($con,"INSERT INTO ratings (storyidr, rank, entry_date)
VALUES ('$_GET[id]','$_POST[starno]',now())");
mysqli_close($con);
?>
答案 0 :(得分:1)
您可以在表单中添加隐藏的输入字段,其中包含ID作为值。