这是我的代码检查,并给我任何建议,谢谢StackOverflow团队
<video onclick="
<?php
$slectips = "SELECT * FROM unique_visitors WHERE ipaddress = '$uuser_id'";
$checkipNumber = mysqli_query($conn,$slectips);
$numbersofviews = mysqli_num_rows($checkipNumber);
if($numbersofviews==0)
{
$insertips = "INSERT INTO `unique_visitors`(`ipaddress`) VALUES ('$uuser_id')";
$Ipquery = mysqli_query($conn,$insertips);
if($Ipquery==true)
{
$insertview = "UPDATE `videos` SET `views`= views +1 WHERE id = '".$row['id']."'";
$Viewquery = mysqli_query($conn,$insertview);
if($Viewquery==true)
{
echo "<script>alert('Suceessfully Ips Adress And Views Inseted');</script>";
}
else
{
echo "<script>alert('ERROR UPDATING VIEW');</script>";
}
}
else
{
echo "<script>alert('ERROR INSERTING IPS YOUR IP MATCH');</script>";
}
}
else
{
echo "<script>alert('Your Ip AVAILABLE IN DATABASE');</script>";
}
?>
" id='my_video' src="<?php echo $images; ?>" controls></video>
请帮助我,我不知道如何在不刷新页面的情况下计算视频观看次数并插入PHP中的数据库中
答案 0 :(得分:0)
正如我在这里所说的,如何在ONCLICK中使用AJAX的示例
//page one1
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<video onclick="sendcount('<?php echo $uuser_id;?>')" id='my_video' src="<?php echo $images; ?>" controls></video>
<script>
function sendcount(uuser_id)
{
$.ajax({
type: "POST",
url: "page2.php",
data: {"uuser_id":uuser_id},
async: true,
success: function(data){
var obj = JSON.parse(data);
alert(obj.msg);
}})
}
</script>
</body>
</html>
// page 2
<?php
$uuser_id=$_POST['uuser_id'];
$msg='';
$slectips = "SELECT * FROM unique_visitors WHERE ipaddress = '$uuser_id'";
$checkipNumber = mysqli_query($conn,$slectips);
$numbersofviews = mysqli_num_rows($checkipNumber);
if($numbersofviews==0)
{
$insertips = "INSERT INTO `unique_visitors`(`ipaddress`) VALUES ('$uuser_id')";
$Ipquery = mysqli_query($conn,$insertips);
if($Ipquery==true)
{
$insertview = "UPDATE `videos` SET `views`= views +1 WHERE id = '".$row['id']."'";
$Viewquery = mysqli_query($conn,$insertview);
if($Viewquery==true)
{
$msg="alert('Suceessfully Ips Adress And Views Inseted');";
// echo "<script>alert('Suceessfully Ips Adress And Views Inseted');</script>";
}
else
{$msg="ERROR UPDATING VIEW";
// echo "<script>alert('ERROR UPDATING VIEW');</script>";
}
}
else
{$msg="ERROR INSERTING IPS YOUR IP MATCH";
//echo "<script>alert('ERROR INSERTING IPS YOUR IP MATCH');</script>";
}
}
else
{$msg="Your Ip AVAILABLE IN DATABASE";
//echo "<script>alert('Your Ip AVAILABLE IN DATABASE');</script>";
}
$json_data = array(
"msg" => $msg,
);
echo json_encode($json_data); // send data as json format
die;
?>