gpt4 book ai didi

html - 将 URL 参数与 mySQL 和 JSP 一起使用时出现错误

转载 作者:行者123 更新时间:2023-11-29 22:54:20 26 4
gpt4 key购买 nike

该代码连接到 mySQL 数据库并创建一个表并用数据填充该表。每行都有一个特定于该行的购买按钮。这样具体的item代码就会被发送到jsporder.jsp页面。

<sql:query var="result">
select * from inventory;
</sql:query>

<table border="1" width="100%">
<tr>
<th>Code</th>
<th>Author</th>
<th>Description</th>
<th>Other field(Probs price)</th>
<th>Item Stock</th>
<th>Order Stock</th>
<th>Buy option </th>
</tr>

<c:forEach var = "row" items = "${result.rows}">
<tr>
<td><c:out value = "${row.item_code}"/></td>
<td><c:out value = "${row.item_author}"/></td>
<td><c:out value = "${row.item_description}"/></td>
<td><c:out value = "${row.item_price}"/></td>
<td><c:out value = "${row.item__stock_count}"/></td>
<td><c:out value = "${row.item_order_count}"/></td>
<td><a href="jsporder.jsp?item_code=${row.item_code}">Buy!</a></td>
<td><a
</tr>
</c:forEach>
</table>
</div>

现在我的 Jsp 订单页面我想要更改数据库中的数据。

首先使用:

String itemCode = request.getParameter("item_code");

我认为它从上一页获取了 item_code ?

现在我需要更改 mySQL 查询:

<sql:update var="count">
<%-- update inventory - take one item from stock --%>
update inventory set item__stock_count = item__stock_count - 1
where item_code="${itemCode}"; //This is set to the itemCode variable
</sql:update>

item_code 与 itemCode 不匹配。它似乎没有选择 itemCode 作为任何内容,因此它不会更改数据库中的值/在数据库中添加任何条目。

itemCode 变量对于 jsp/mysql 来说似乎不存在。

新的网络开发人员。谢谢(额外)

        <sql:update var="count">
<%-- add new customer_order --%>
insert into customer_order values
( '${itemCode}' "2015-02-24 11:42:30", 1,
"2015-02-25 11:42:30", 5789 );
</sql:update>

页面上显示的内容:

insert into customer_order values ( '' "2015-02-24 11:42:30", 1, "2015-02-25 11:42:30", 5789 ); : Column count doesn't match value count at row 1"

最佳答案

将您的购买链接更改为

<a href="jsporder.jsp?itemCode=${row.item_code}">Buy!</a>

并从 jsporder.jsp 中删除以下内容,因为此时不需要它。

String itemCode = request.getParameter("item_code");

此外,您可能需要在此处的更新查询中使用逗号。

  insert into customer_order values
( '${param.itemCode}', "2015-02-24 11:42:30", 1,
^
"2015-02-25 11:42:30", 5789 );

验证您的 customer_order 表有五列并且数据类型匹配。

关于html - 将 URL 参数与 mySQL 和 JSP 一起使用时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28782920/

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