gpt4 book ai didi

javascript - 如何在 MySQL 插入语句中包含 JavaScript 变量值

转载 作者:行者123 更新时间:2023-11-29 18:11:04 42 4
gpt4 key购买 nike

我在 Java 脚本变量的帮助下获取了一些值。我尝试将这些值插入到 Bizmapper (Bizlink) 中的 DB (MySQL) 中,但它引发了一些错误:

[Error is --> " Failed to execute SQL insert into po_ref_table values (4200913801AA, DEAM, 067,Joseph Keefe,jkeefe@synovos.com,W.W. Grainger, Inc.) failed to execute. Reason: 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 'Keefe,jkeefe@synovos.com,W.W. Grainger, Inc.)' at line 1."].

我尝试了下面提到的这种方式:

MySQL_DB.open(true);

// Get necessory data //
var erp_PONum = mek.targetDocument.getRootSegment("ST").getSegment("BEG").getEDIElement("BEG03").getData();
var erp_OriginSystem = mek.targetDocument.getRootSegment("ST").getSegment("BEG").getRecord("WFG_BEG").getField("WF_OriginSystem").getData();
var erp_SiteCode = mek.targetDocument.getRootSegment("ST").getSegment("BEG").getRecord("WFG_BEG").getField("WF_SiteCode").getData();
var erp_BuyerName = mek.targetDocument.getRootSegment("ST").getSegment("BEG").getRecord("WFG_BEG").getField("WF_BuyerName").getData();
var erp_BuyerEmail = mek.targetDocument.getRootSegment("ST").getSegment("BEG").getRecord("WFG_BEG").getField("WF_BuyerEmail").getData();
var erp_SupplierName = mek.targetDocument.getRootSegment("ST").getSegment("BEG").getRecord("WFG_BEG").getField("WF_SupplierName").getData();

//Inser into Table//

MySQL_DB.command("insert into po_ref_table Values ("+ erp_PONum +", "+ erp_OriginSystem +", "+ erp_SiteCode +","+ erp_BuyerName +","+ erp_BuyerEmail +","+ erp_SupplierName +")");

//Close DB//

MySQL_DB.close();

我该如何解决这个问题?

最佳答案

谨防 SQL 注入(inject)漏洞!在查询中使用参数持有者。

var args = [erp_PONum, erp_OriginSystem, erp_SiteCode, erp_BuyerName, erp_BuyerEmail, erp_SupplierName];
MySQL_DB.command("insert into po_ref_table Values (?,?,?,?,?,?)",[args]);

关于javascript - 如何在 MySQL 插入语句中包含 JavaScript 变量值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47400849/

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