gpt4 book ai didi

javascript - 需要帮助来查找我的查询中的语法错误

转载 作者:太空宇宙 更新时间:2023-11-03 10:37:36 24 4
gpt4 key购买 nike

我正在编写一个程序来操纵用户输入的时间。当从 JavaScript 推送变量时,我编写了以下 PHP 来从服务器检索用户详细信息。

我的问题是 SQL 在变量 :uid 附近抛出一个 fatal error 。

这是我得到的完整错误,

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':uid' at line 1' in ***\TimSheetSystem\bin\Functions\getUsrId.php on line 25

这是我的javascript,

function getUser2(){

var selUser = document.getElementById("uid").value;

if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}

xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("userSelect").innerHTML=xmlhttp.responseText;
}
};
xmlhttp.open("POST","../functions/getUsrId.php?uid=getUsr2&selUser="+selUser,true);
xmlhttp.send();

这是带有查询的 PHP,

$getSelUsr = "SELECT * FROM userlogin WHERE uId = :uid";
$getSelUsrQuery = $dbConnect -> query($getSelUsr);
$getSelUsrQuery -> bindParam(':uid', $_REQUEST["selUser"]);
$getSelUsrQuery -> execute();
$getSelUsrRow = $getSelUsrQuery -> fetch(PDO::FETCH_ASSOC);

echo "<option id= ".$getSelUsrRow["uId"].">".$getSelUsrRow["fName"]." ".$getSelUsrRow["lName"]."</option>";

我查看并检查了所有 semi,并尝试不使用 JavaScript 直接推送数据,但我仍然一遍又一遍地遇到相同的错误。

有人可以发现我做错了什么吗。

编辑1这是通过定时函数调用程序调用 getUser2 函数的页面。

主页面,

<?php if ($_SESSION["sT"] == "Done"){ ?>
<body onload="tEditReload2()">
<div id="divCenter-timeEdit" class="box">
<label id="sbId" hidden><?php echo $_SESSION["uRole"]?></label>
<div class="logo-timeEdit">
<img src="../../images/logo.png" width="142" height="33">
</div>
<div id="mainDiv" style="height: 38px;">
<label for="dPicker">Date:</label>
<input type="text" id="dPicker" style="margin-left: .5%;" size="10" value="<?php echo $getStermRow["sDate"]; ?>">
<label for="userSelect" style="margin-left: 2%">Select User:</label>
<select id="userSelect" style="width:160px; margin-left: .5%;" onchange="usrId(this.id);"></select>
<input type="text" id="uid" size="1" value="<?php echo $getStermRow["sUid"]; ?>" hidden>
<input type="button" class="getData" value="Submit" onclick="getData();">
</div>
<div id="resultTable"><span id="noDataMsg"></span> </div>2
</div>
</body>

定时函数调用,

function tEditReload2() {
getUser2();
setTimeout("getData();",100);
}

最佳答案

尝试改变:

$getSelUsrQuery = $dbConnect -> query($getSelUsr);

$getSelUsrQuery = $dbConnect ->prepare($getSelUsr);

你是否丢弃了 $uid?它是有效值吗?

关于javascript - 需要帮助来查找我的查询中的语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45183346/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com