我试图在php中创建一个喜欢/不同的按钮。我的代码运行正常。我有一个类似的按钮,当我点击它时,它将数据传输到我的数据库中的“喜欢”表。我唯一的问题是,当我点击一个类似的按钮时,我无法自动更改为不同的按钮。知道怎么做吗?
“; $ _SESSION [ 'PID'] = $行[ 'ID']; $的userid = $ _ SESSION [ '用户ID']; echo $ userid; ?&GT; “&GT;像<?php
require '../connection/config.php';
$id=$_GET['id'];
$userid=$_SESSION['userid'];
$postid=$id;
{
$sql="select * from post inner join likenew on post.id=likenew.id where userid='$userid' and postid='$id'";
echo $sql;
$result=mysqli_query($conn,$sql);
$row=mysqli_fetch_array($result);
if($row['status']=='')
{
$sql="insert into likenew(postid,userid) values('$id','$userid')";
$result=mysqli_query($conn,$sql);
echo $sql;
}
if($result)
{
$sql="update likenew set status=1 where postid='$id' and userid='$userid'";
$result=mysqli_query($conn,$sql);
echo $sql;
}
elseif($row['status']=='1')
{
$sql="update likenew set status=0,status2='unlike' where postid='$id' and userid='$userid'";
$result=mysqli_query($conn,$sql);
echo $sql;
}
elseif($row['status']=='0')
{
$sql="update likenew set status=1,status2='like' where postid='$id' and userid='$userid'";
$result=mysqli_query($conn,$sql);
echo $sql;
}
}
/*if($result)
{
header('location:likedisplay.php');
}
else
{
echo "error";
}
}
if($num==1){
$sql="insert into likenew(postid,userid) values('$id','$userid')";
$result1=mysqli_query($conn,$sql1);
}
else
{
$sql1="update likenew set status=1 where postid='$id' and userid='$userid'";
$result=mysqli_query($conn,$sql);
if($result)
{
header('location:likedisplay.php');
}
else
{
echo "error";
}
}*/
?>
答案 0 :(得分:0)
可能是你可以使用javascript和OnClick的东西,如:
<input type='submit' name='like' OnClick='stuff()'>
然后是东西:
<script>
function stuff(){
//change the button name here
}
</script>