您在 home.html 中选择产品,然后 JS 中的 cookie 和函数会将信息解析为 manage.html 然后在 manage.html 中您可以填写您的信息并将其发送到 mail.php 然后 mail.php 将查看客户是否已经在数据库中,如果没有,它将添加。然后它将订单添加到数据库中。
其他都行,只有最后一步添加订单到数据库是不行的,因为我不知道怎么把manage.html中的JS拿到mail.php。
我正在尝试使用类似 $_GET["something"]; 在 mail.php 中,从解析为 manage.html 的 JavaScript 获取信息。
COOKIES.JS 中的代码
function readCookies(name){
var nameCookie = name + "=";
var cookieArray = document.cookie.split(';');
for (var i=0; i < cookieArray.length; i++){
var thisCookie = cookieArray[i]
while (thisCookie.charAt(0) ==' '){
thisCookie = thisCookie.substring(1,thisCookie.length);
}
if (thisCookie.indexOf(nameCookie) == 0){
return thisCookie.substring(nameCookie.length,thisCookie.length);
}
}
return null;
}
FUNCTION.JS 中的代码:
function cartShow(){
NumberOrdered = 0;
NumberOrdered = readCookies("NumberOrdered");
tableRow = "";
for (i = 1; i <= NumberOrdered; i++){
NewOrder = "Order" + i;
thisCookie = readCookies(NewOrder);
fields = new Array();
fields = thisCookie.split("|");
tableRow += "<tr>"
+ "<td>" + fields[0] + "</td>"
+ "<td>" + fields[1] + "</td>"
+ "<td>" + fields[2] + "</td>"
+ "<td>" + fields[3] + "</td>"
+ "<td>" + fields[4] + "</td>"
+ "<td>" + fields[3] * fields[4] + "</td>"
+ "<td>" + "<img src=\"includes/images/delete.png\"/ OnClick=\"DeleteItem(" + i + ")\">" + "</td>"
+ "</tr>";
}
document.write(tableRow);
}
function fillInForm(){
NumberOrdered = 0;
NumberOrdered = readCookies("NumberOrdered");
for (i = 1; i <= NumberOrdered; i++){
NewOrder = "Order" + i;
thisCookie = "";
thisCookie = readCookies(NewOrder);;
fields = new Array();
fields = thisCookie.split("|");
document.write("<input type=hidden name=\"Product ID " + " " + i + "\" value=\"" + " " + fields[0] + "\">");
document.write("<input type=hidden name=\"Brand " + " " + i + "\" value=\"" + " " + fields[1] + "\">");
document.write("<input type=hidden name=\"Model " + " " + i + "\" value=\"" + " " + fields[2] + "\">");
document.write("<input type=hidden name=\"Price " + " " + i + "\" value=\"" + " " + fields[3] + "\">");
document.write("<input type=hidden name=\"Amount products " + " " + i + "\" value=\"" + " " + fields[4] + "\">");
document.write("<input type=hidden name=\"Total cost " + " " + i + "\" value=\"" + " " + fields[3] * fields[4] + "\">");
document.write("<input type=hidden name=\" " + "\" value=\"" + "\">");
}
}
然后用于在 MANAGE.HTML 上显示一些产品信息:
<form action="mail.php" enctype="text/plain" onSubmit="return checkForm(this);" method="get">
<table border=1 summary="">
<tr>
<td bgcolor=#cccccc><b><p name="id"> id</p></b></td>
<td bgcolor=#cccccc><b> brand</b></td>
<td bgcolor=#cccccc><b> model</b></td>
<td bgcolor=#cccccc><b> price</b></td>
<td bgcolor=#cccccc><b> number</b></td>
<td bgcolor=#cccccc><b> total</b></td>
<td bgcolor=#cccccc><b> delete</b></td>
</tr>
<script>
cartShow();
fillInForm();
</script>
</table>
<input type="image" src="includes/images/checkout.png" alt="" value="send" />
</form>
在此之后,我需要获取 MAIL.PHP 中的信息。
因为<script>cartShow(); fillInForm();</script>
在manage.html中是显示表格中的信息,不知道怎么才能把它放到MAIL.PHP中。
我希望有人可以帮助我,我在过去的 5 个小时里一直在努力解决这个问题。