Ben mysqli için mysql benim php kodu değişti nedense her şey berbat oldu.
Bir kullanıcı bir derece girdiğinde Örneğin, benim mysql tablo yeni bir satır girmek ve doğru satır güncelleyerek kez günceller. Ben sadece hiçbir satır varsa o birine girdiği görmek için yeni bir satır ve kontroller güncellemeleri yüzden nasıl bu sorunu gidermek merak ediyorum?
PHP kodu
// function to insert rating
function rate(){
$dbc = mysqli_connect ("localhost", "root", "", "sitename");
$text = strip_tags($_GET['rating']);
$update = "update vote set counter = counter + 1, value = value + ".$_GET['rating']."";
$result = mysqli_query($dbc,$update);
if(mysqli_affected_rows() == 0){
$insert = "insert into vote (counter,value) values ('1','".$_GET['rating']."')";
$result = mysqli_query($dbc,$insert);
}
}
Eski kodu php
// function to insert rating
function rate(){
$text = strip_tags($_GET['rating']);
$update = "update vote set counter = counter + 1, value = value + ".$_GET['rating']."";
$result = mysql_query($update);
if(mysql_affected_rows() == 0){
$insert = "insert into vote (counter,value) values ('1','".$_GET['rating']."')";
$result = mysql_query($insert);
}
}