php - Use boolean value received from mysql query to update a value -


i need switching boolean value in field in small mysql db. created index.php shows names , presence field (present/away). use boolean. value clickable, should switch boolean value. here relevant code:

$id=$_get['id'];  $qresult = mysqli_query($con,"select present personnel inlogcode='$id'");  $result=mysql_fetch_array($qresult); $presence = (bool)$result;  echo "id is: " .$id . "<br>"; echo "boolean res is: " . $presence . "<br>";  if ($presence) {     $sql="update personnel set present=true inlogcode='$id'";     $resultaat=mysql_query($sql); }     else {     $sql="update personnel set present=false inlogcode='$id'";     $resultaat=mysql_query($sql); } 

i cannot find out how convert result of query true boolean value can use in rest of php script. adding mysql_fetch_array seems unnecessary, seem lose boolean value zero's or one's. test db of course contains both values.

you can update single query:

update personnel set present = 1 - present inlogcode=? 

consider using pdo , prepared statements. current query vulnerable sql injection attack


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -