PHP affected lines = 1 will not work properly

My script:

<?php
ob_start();
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header('Content-type: text/html; charset=utf-8');
include "tilslut.php";
$userid = $_GET["userid"];
$s = mysql_query("SELECT points, lastpoint FROM member_profile WHERE user_id = '".$userid."'");
$n = mysql_fetch_array($s);
$tid = time(); 
mysql_query("UPDATE member_profile set points = points+1, lastpoint=$tid  WHERE lastpoint<=$tid-60 AND user_id = '".$userid."'");
$e = mysql_query("SELECT points FROM member_profile WHERE user_id = '".$userid."'");
$f = mysql_fetch_array($e); 
if (mysql_affected_rows() == 1) {
$s = mysql_query("SELECT points FROM member_profile WHERE user_id = '".$userid."'");
$n = mysql_fetch_array($s);
?>
Inserted!
<?
}else{
echo "Already got";
}
ob_flush();
?>

I have this to give points. The update request works and gives only a point if lastpoint <= time () is 60, but it still says “Insert”, even if it does not insert. I tried using the rows affected by mysql to check whether it was affected or not, but this does not seem to work.

+3
source share
3 answers

you need to call mysql_affected_rows right after the update before making another choice. mysql_affected_rows will only work with the last query executed on the connection.

+3
source

Your location is:

  • query execution update
  • then run the selectquery
  • , , mysql_affected_rows

, mysql_affected_rows update, : mysql_affected_rows - 't select , , .


: SQL Injection, : SQL- ( $_GET["userid"]) , , , .


: $e, $f, $n, $s,... //: - (

+3

$e = mysql_query("SELECT points FROM member_profile WHERE user_id = '".$userid."'");  

, .

+1

Source: https://habr.com/ru/post/1732905/


All Articles