我檢查如果網址首先存在,看看他是否第一次投票,如果是的話,那麼我會添加用戶聲譽upvoted列,但我想只添加到該網址不是所有的URL,這段代碼添加到「upvotes」列中的所有元組,我希望它只添加到特定的元組。需要更新只有一個元組,但這是更新整個列在表
<!Doctype html>
<html>
<?php
$c=$_GET['a'];// users name
$d=$_GET['b'];// usesrs id
$e=$_GET['c'];// users repute
$ur=$_POST['url'];
// Create connection
$con=mysqli_connect("localhost","root","","repute system");
if(mysqli_connect_errno()){
echo "ERROR ".mysqli_connect_error();
}
$sql = mysqli_query($con,"SELECT * FROM sites");
if (mysqli_num_rows($sql) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($sql))
{
if($ur == $row['URL'] && $d != $row['id'])
{
$ne = $row['upvotes'] + $e;
$sol = mysqli_query($con, "UPDATE sites SET upvotes = $ne ");
$bew = mysqli_query($con,"INSERT INTO v_sites(teacher_id,URL,vote) VALUES ('$d','$ur','$e')");
echo "Upvoted the site ";
echo $ur;
}
}
} else {
echo "Sorry before upvoting you have to block it first or you are trying to upvote your own report, in which you cant";
}
?>
</html>
您需要更新語句中的where子句。 – Maximus2012
它應該更新哪個特定的元組?它應該怎麼知道它是什麼? – Barmar
'更新網站設置upvotes = $ ne'是的,這樣做。如上所述....哪裏在哪裏?請閱讀更新https://dev.mysql.com/doc/refman/5.0/en/update。html –