将整数变量插入数据库


inserting integer variable into Database

如何将这个 int 值放入我们的数据库中?我试过在 $_POST 之前放置 (int( 和 intval,但它仍然不起作用?除了该 int 值的转换(?(之外,其他所有工作都可以工作,因此可以将其放置在我们的数据库中。我们是否遗漏了代码中的任何内容?提前谢谢你。

function computeScoregrammar(){
                       // code for computing the score here
                       aver = 5; 
<?php 
 //db connection here
    $avegs = $_POST['aver'];
    $qidScores = 4; 
//below part is not yet complete for we are only trying to update a sample data in the database
    if($qidScores == 4){
      $qs = "UPDATE scores SET GrammarScore = '$avegs' WHERE applicantID = '$qidScores'";
      mysqli_query($conn,$qs);
      mysqli_close($conn);
    }
    else { 
        //else statement here
    }
      ?>    

试试看:

$qs = "UPDATE scores SET GrammarScore = $avegs WHERE applicantID = '$qidScores'";

$avegs不使用''。如果使用 ''$avegs将被视为字符串。

警告:SQL注入,不要把它放到网上!使用 PDO 或转义 ( mysqli_escape_string() ( 并删除''