将整数变量插入数据库

时间:2016-04-13 07:55:33

标签: javascript php html

如何将此int值放入数据库?我在$ _POST之前尝试过put(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
    }
      ?>    

2 个答案:

答案 0 :(得分:0)

试一试:

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

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

答案 1 :(得分:0)

警告: SQL注入,请勿将此在线!使用PDO或转义(mysqli_escape_string())并删除''

相关问题