为什么我的IP检查方法不起作用? PHP / MySQL

时间:2018-11-04 17:07:49

标签: php mysql sql mysqli

为什么我尝试通过IP地址检查两次投票是否正常?

make_plots <- function (variable_string) {
  var_quo <- rlang::sym(variable_string)
  hist = qplot(!!var_quo, data = full_data_noNO, geom="histogram", 
               fill=I("lightblue"))+
    theme_light()

  avg_price = full_data_noNO %>% 
    group_by(Month, Country) %>%
    dplyr::summarize(avg = mean(!!var_quo, na.rm = 
                                  TRUE))

  #line graph for different countries over time
  line = ggplot(data=avg_price, aes(x=anydate(Month), y=!!var_quo, 
                                    group=Country)) +
    xlab("Date")+
    ylab(variable_string)+
    geom_line(aes(color=Country), size = 1)+
    theme_light()

  #boxplot over different years
  avg_price2 = avg_price
  avg_price2$Month = format(as.Date(anydate(avg_price$Month), "%Y-%m-%d"), 
                            "%Y")

  box = ggplot(avg_price2, aes(x = Month, y=!!var_quo, fill = Month)) + 
    geom_boxplot()+
    xlab("Date")+
    ylab(variable_string)+
    guides(fill=FALSE)+
    theme_light()

  var_name = grid.text(!!var_quo, gp=gpar(fontsize=20))

  #merge plot into one window
  combined <- grid.arrange(var_name, hist, line, box, ncol=2)

  # Save combined plot at VARIABLE_plots.pdf
  ggsave(paste0(variable_string, "_plots.pdf"), combined)
  combined
}

# Make sure to pass the variable names as character vector
plots <- lapply(c("VARIABLE1", "VARIABLE2"), make_plots)
# OR
plots <- lapply(colnames(full_data_noNO), make_plots)

# Plots can also be accessed and printed individually
print(plots[["VARIABLE1"]])

MySQLI Table

前一段时间对其进行了测试,一切都很好。但是现在我可以投票了。

1 个答案:

答案 0 :(得分:0)

尝试一下:

    if ($qtype === "sc"){
            // single choice has only one select item



            // check whether user has already answered this question
            $i=0;
            $res = mysqli_query($mysqli, "SELECT ip FROM votedanswers WHERE ip = \"".$ip."\" and qID = \"".$qID."\"");

            while($obj = mysqli_fetch_assoc($res))
            {
              $i = $i+1;
            }                   
            if ($i > 0){
                echo "your vote has already been counted";
            }
            else{
                //insert data
                $res = mysqli_query($mysqli, "INSERT INTO votedanswers (ip, qID, qQuestion, aID) VALUES ('$ip', '$qID', '$quest', '$aID')");
                echo "your vote has been counted";
            }   



    } else {
        echo "nope!";
    }

另请参阅:How can I prevent SQL injection in PHP?