I'm trying to check if the leaguename
name already exists if it does then check if it is higher than the existing score. if its higher then replace the quizscore
else insert the leaguename
and quizscore
into the table league_quiz.
The code seem to insert the values in my table, but it do not seem update if the name is equal to previous and the score is higher?
I get this error:
Warning:
mysqli_num_rows()
expects parameter 1 to bemysqli_result
, string given in
My code:
<?php
$name = (string)$_POST['name'];
$score = (string) $_POST['score'];
$link = mysqli_connect("mysql12.gigahost.dk","username","password","dirts_mysql");
$query = "SELECT leaguename, quizscore FROM league_quiz WHERE leaguename = '$name' AND quizscore < '$score'";
if(mysqli_num_rows($query)) {
mysqli_query($link,"UPDATE league_quiz SET quizscore = '$score'");
} else {
mysqli_query($link,"INSERT INTO league_quiz (leaguename, quizscore) VALUES ('$name', '$score')") or die(mysqli_error($link));
}
?>