PHP & Mysql database updating problem

liberty

New Member
For some reason when I changed my php code from mysql to mysqli everything got messed up.For example, when a user enters a rating my mysql table updates twice by entering one new row and updating the correct row. I was wondering how do I correct this problem so it only updates the new row and checks to see if there is no row it enters one?PHP code\[code\]// function to insert ratingfunction rate(){ $dbc = mysqli_connect ("localhost", "root", "", "sitename"); $text = strip_tags($_GET['rating']); $update = "update vote set counter = counter + 1, value = http://stackoverflow.com/questions/2071549/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); }}\[/code\]old php code\[code\]// function to insert ratingfunction rate(){ $text = strip_tags($_GET['rating']); $update = "update vote set counter = counter + 1, value = http://stackoverflow.com/questions/2071549/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); }}\[/code\]
 
Back
Top