drne47241 2017-11-27 13:55
浏览 49
已采纳

PDO SQLSTATE [HY093]:参数号无效:参数未定义[重复]

This question already has an answer here:

I have an idea of what the error means but for the life of me I can't find it no matter how hard I check and rewrite. Been at it for a while, need a fresh pair of eyes to see where I'm going wrong.

The update function

public function student_acadbg_update($acadbgID, $LRN, $gradesix, $gradesixyear, $gsixawards, $gradeten, $gradetenyear, $gtenawards, $orgs, $extraawards)
{
    try
    {
        $query=$this->db->prepare("UPDATE tb_student_acadbg SET LRN = :LRN,
                                                        gradesix = :gradesix,
                                                        gradesixyear = :gradesixyear,
                                                        gsixawards = :gsixawards,
                                                        gradeten = :gradeten,
                                                        gradetenyear = :gradetenyear,
                                                        gtenawards = :gtenawards,
                                                        orgs = :orgs,
                                                        extraawards = :extrawards
                                                        WHERE acadbgID = :acadbgID");
        $query->bindParam(":LRN", $LRN, PDO::PARAM_STR);
        $query->bindParam(":gradesix", $gradesix, PDO::PARAM_STR);
        $query->bindParam(":gradesixyear", $gradesixyear, PDO::PARAM_STR);
        $query->bindParam(":gsixawards", $gsixawards, PDO::PARAM_STR);
        $query->bindParam(":gradeten", $gradeten, PDO::PARAM_STR);
        $query->bindParam(":gradetenyear", $gradetenyear, PDO::PARAM_STR);
        $query->bindParam(":gtenawards", $gtenawards, PDO::PARAM_STR);
        $query->bindParam(":orgs", $orgs, PDO::PARAM_STR);
        $query->bindParam(":extraawards", $extraawards, PDO::PARAM_STR);
        $query->bindParam(":acadbgID", $acadbgID, PDO::PARAM_INT);
        $query->execute();

        return true;
    }
    catch(PDOException $e)  
    {
    echo $e->getMessage();
    return false;
    }   
}

Where the user input is collected and where the function is called

if(isset($_POST['btn-update']))
{
$LRN = $_GET['LRN'];
$acadbgID = $_POST['acadbgID'];
$gradesix = $_POST['gradesix'];
$gradesixyear = $_POST['gradesixyear'];
$gsixawards = $_POST['gsixawards'];
$gradeten = $_POST['gradeten'];
$gradetenyear = $_POST['gradetenyear'];
$gtenawards = $_POST['gtenawards'];
$orgs = $_POST['orgs'];
$extraawards = $_POST['extraawards'];

if($crud->student_acadbg_update($acadbgID, $LRN, $gradesix, $gradesixyear, $gsixawards, $gradeten, $gradetenyear, $gtenawards, $orgs, $extraawards))
{
    $msg = "<div class='alert alert-info'>
            <strong>WOW!</strong> Record was inserted successfully! <a href='student.php'>Click here to see!</a>
            </div>";
}
else
{
    $msg = "<div class='alert alert-warning'>
            <strong>SORRY!</strong> you fucked up !
            </div>";
     }
}

This is the 2nd part in a two part process the user goes through with registration and LRN is my main reference point to bind various other table entries and details to a specific person. I have no issue getting the data from the database according to the LRN but for some reason this update isn't working whereas my 10+ other CRUD functions are all working fine. I just can't figure it out.

I originally skipped the 'acadbgID' variable since it's just an auto-increment field in my DB that I have yet to really put to use. I've skipped similar auto-increment fields in my other Update functions but out of frustration I decided to try putting it in but still no cigar.

Sorry if it's a bit messy, I just put it together to test core functionality, polishing will be for when everything actually works properly. Just let me know if there are any details I need to add. Thanks in advance.

P.S. If anyone sees any bad practices please do point them out, I am still learning as I go so I'm sure there's room for improvement.

</div>
  • 写回答

1条回答 默认 最新

  • duanping6698 2017-11-27 13:59
    关注

    you have a mismatch between the SQL parameter placeholder and the bind parameter specification.

    extrawards in SQL is not same as extraawards in bind

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 yolov8边框坐标
  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真