gpt4 book ai didi

php - 提交表单时将变量传递到数据库时遇到问题

转载 作者:行者123 更新时间:2023-11-29 23:53:51 24 4
gpt4 key购买 nike

我有 3 个 php 文件。第一个dispatch.php创建一个表单,其中包含您必须从中选择的员工(必须传递的变量)的下拉选择,并显示带有数据行的dispatch2.php。每行的第一列是一个复选框,=订单号(必须传递的变量)。第二列显示该订单号。然后我们还有其他列,其中一列是订单年龄。该列获取订单时间(要传递的变量)并计算年龄(要传递的变量)。因此,您选择员工、适当的复选框并单击提交。

Dispatch.php 和dispatch2.php 显示正常。当我点击提交时出现错误。因此,我没有写入数据库,而是回显了该变量,但没有得到任何结果。它显示的唯一内容是非变量 OTD。

这里是dispatch_post.php,仅包含变量的回显。

<?php
echo $orders->fields['order_id'];
echo $orders->fields['date_purchased'];
echo $result->fields['employee_id'];
echo $difference;
echo 'OTD';
?>

每当提交表单时,“OTD”都应该写入表中的状态列,因此我没有将其更改为变量。如果我应该让我知道。

这是我制作的第一个表格。因此,如果这很简单并且我没有看到错误,我深表歉意。

这是我的文件。调度.php

    <?php
/**
* @package admin
* @copyright Copyright 2003-2013 Zen Cart Development Team
* @copyright Portions Copyright 2003 osCommerce
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version GIT: $Id: Author: DrByte Wed Nov 6 21:04:33 2013 -0500 Modified in v1.5.2 $
*/

require('includes/application_top.php');

// unset variable which is sometimes tainted by bad plugins like magneticOne tools
if (isset($module)) unset($module);

require(DIR_WS_CLASSES . 'currencies.php');
$currencies = new currencies();

if (isset($_GET['oID'])) $_GET['oID'] = (int)$_GET['oID'];

include(DIR_WS_CLASSES . 'order.php');

?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/dispatch.css">
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function(){
// load text file when page loads
$("#div1").load("https://secure3243.hostgator.com/~w57dsjmm/order/ducky/dispatch2.php");

// Then reload it every 5 seconds, for ever ...
setInterval(function(){
$("#div1").load("https://secure3243.hostgator.com/~w57dsjmm/order/ducky/dispatch2.php");
}, 5000);
});
</script>
</head>
<body onLoad="init()">
<!-- header_eof //-->
<!-- body //-->
<!-- body_text //-->
<p><a href="http://order.southshorepizza.net/ducky">ADMIN</A>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Dispatch Screen</p>
<form action="dispatch_post.php" method="post">
<div class="dropdown" valign="center">
<select required name="dropdown">
<option value="Select Driver" selected>Select Driver</option>
<?php
$result = $db->Execute("SELECT * FROM " . TABLE_EMPLOYEES);
while (!$result->EOF) {
echo '<option value="' . $result->fields['employee_id'] . '">' . $result->fields['employee_first'] . '</option>';
$result->MoveNext();
}
?>
</select>
</div>
<table border="0" width="100%" cellspacing="0" cellpadding="2">
<tr class="dataTableHeadingRow">
<td class="dataTableHeadingContent" width="10%" align="center"><?php echo "Dispatch"; ?></td>
<td class="dataTableHeadingContent" width="20%" align="center"><?php echo TABLE_HEADING_ORDERS_ID; ?></td>
<td class="dataTableHeadingContent" width="30%" align="center"><?php echo "Address"; ?></td>
<td class="dataTableHeadingContent" width="20%" align="center"><?php echo "Order Age"; ?></td>
<td class="dataTableHeadingContent" width="20%" align="center"><?php echo TABLE_HEADING_ORDER_TOTAL; ?></td>
</tr>
</table>
<div id="div1">
</div>
<input type="submit">
</form>
</div>
<!-- body_eof //-->
</body>

dispatch2.php

<?php
/**
* @package admin
* @copyright Copyright 2003-2013 Zen Cart Development Team
* @copyright Portions Copyright 2003 osCommerce
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version GIT: $Id: Author: DrByte Wed Nov 6 21:04:33 2013 -0500 Modified in v1.5.2 $
*/

require('includes/application_top.php');

// unset variable which is sometimes tainted by bad plugins like magneticOne tools
if (isset($module)) unset($module);

require(DIR_WS_CLASSES . 'currencies.php');
$currencies = new currencies();

if (isset($_GET['oID'])) $_GET['oID'] = (int)$_GET['oID'];

include(DIR_WS_CLASSES . 'order.php');

?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/dispatch.css">
<link rel="stylesheet" type="text/css" href="includes/cssjsmenuhover.css" media="all" id="hoverJS">
</head>
<body onLoad="init()">
<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2">
<!-- body_text //-->
<tr>
<?php
$new_fields = ", o.delivery_street_address, o.shipping_module_code ";

$orders_query_raw = "select " . $search_distinct . " o.orders_id, o.customers_id, o.customers_name, o.payment_method, o.shipping_method, o.date_purchased, o.last_modified, o.currency, o.currency_value, s.orders_status_name, ot.text as order_total" .
$new_fields . "
from (" . TABLE_ORDERS_STATUS . " s, " .
TABLE_ORDERS . " o " .
$new_table . ")
left join " . TABLE_ORDERS_TOTAL . " ot on (o.orders_id = ot.orders_id and ot.class = 'ot_total') " . "
where (o.orders_status = s.orders_status_id and s.language_id = '" . (int)$_SESSION['languages_id'] . "' and o.shipping_module_code LIKE 'Flat' AND orders_status <> 3) " .
$search . " order by o.orders_id DESC";

//echo '<BR><BR>I SEE C: ' . $orders_query_raw . '<BR><BR>';

//last edit before $orders_query_raw }

// Split Page
// reset page when page is unknown
if (($_GET['page'] == '' or $_GET['page'] <= 1) and $_GET['oID'] != '') {
$check_page = $db->Execute($orders_query_raw);
$check_count=1;
if ($check_page->RecordCount() > '15') {
while (!$check_page->EOF) {
if ($check_page->fields['orders_id'] == $_GET['oID']) {
break;
}
$check_count++;
$check_page->MoveNext();
}
$_GET['page'] = round((($check_count/'15')+(fmod_round($check_count,'15') !=0 ? .5 : 0)),0);
} else {
$_GET['page'] = 1;
}
}

// $orders_query_numrows = '';
$orders_split = new splitPageResults($_GET['page'], '15', $orders_query_raw, $orders_query_numrows);
$orders = $db->Execute($orders_query_raw);
while (!$orders->EOF) {
if ((!isset($_GET['oID']) || (isset($_GET['oID']) && ($_GET['oID'] == $orders->fields['orders_id']))) && !isset($oInfo)) {
$oInfo = new objectInfo($orders->fields);
}


?>
<div id="div1">
<td class="dataTableContent" width="10%" align="center"><input type="checkbox" name="otd" value="$orders->fields['orders_id']" /></td>
<td class="dataTableContent" width="20%" align="center"><?php echo $show_difference . $orders->fields['orders_id']; ?></td>
<td class="dataTableContent" width="30%" align="center"><?php echo $orders->fields['delivery_street_address']; ?></td>
<td class="dataTableContent" width="20%" align="center"><?php
$purchase_time = strtotime ($orders->fields['date_purchased']);
$difference = time () - $purchase_time;
$difference_in_minutes = ceil ($difference / 60); //-Round up to the next minute
echo gmdate("H:i:s", $difference);
?></td>
<td class="dataTableContent" width="20%" align="center"><?php echo strip_tags($orders->fields['order_total']); ?></td></div>
</tr>
<?php
$orders->MoveNext();
}
?>
<tr>
<td class="smallText" valign="top" colspan="2"><?php echo $orders_split->display_count($orders_query_numrows, '15', $_GET['page'], TEXT_DISPLAY_NUMBER_OF_ORDERS); ?></td>
<td class="smallText" align="left"><?php echo $orders_split->display_links($orders_query_numrows, '15', MAX_DISPLAY_PAGE_LINKS, $_GET['page'], zen_get_all_get_params(array('page', 'oID', 'action'))); ?></td>
</tr>
</table>
<!-- body_text_eof //-->
<!-- body_eof //-->
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>

最后是dispatch_post.php

<?php
<?php
global $db;
$otd = "otd";
$sql = "insert into " . TABLE_HTA . " (order_id, order_time, employee_id, otd, status) values (:$orders->fields['order_id']:, :$orders->fields['date_purchased']:, :$result->fields['employee_id']:, :$difference:, :'OTD':)";

$sql = $db->bindVars($sql, ':$orders->fields['order_id']:', $valueOne, 'integer');
$sql = $db->bindVars($sql, ':$orders->fields['date_purchased']:', $valueTwo, 'time');
$sql = $db->bindVars($sql, ':$result->fields['employee_id']:', $valueThree, 'integer');
$sql = $db->bindVars($sql, ':$difference:', $valueFour, 'time');
$sql = $db->bindVars($sql, ':$difference:', $valuefive, 'varchar');
$result = $db->Execute($sql);
$newRecordId = $db->Insert_ID();
echo 'The new record added was number: ' . $newRecordId;
?>

任何帮助将不胜感激!

最佳答案

我认为第一个和第二个中的 html 信息负载可能会让你感到困惑。试试这个:

- nwolybug 记录了我的评论

调度.php

<?php
/**
* @package admin
* @copyright Copyright 2003-2013 Zen Cart Development Team
* @copyright Portions Copyright 2003 osCommerce
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version GIT: $Id: Author: DrByte Wed Nov 6 21:04:33 2013 -0500 Modified in v1.5.2 $
*/

require('includes/application_top.php');

// unset variable which is sometimes tainted by bad plugins like magneticOne tools
if (isset($module)) unset($module);

require(DIR_WS_CLASSES . 'currencies.php');
$currencies = new currencies();

if (isset($_GET['oID'])) $_GET['oID'] = (int)$_GET['oID'];

include(DIR_WS_CLASSES . 'order.php');

?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/dispatch.css">
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function(){
// load text file when page loads
$("#div1").load("https://secure3243.hostgator.com/~w57dsjmm/order/ducky/dispatch2.php");

// Then reload it every 5 seconds, for ever ...
setInterval(function(){
$("#div1").load("https://secure3243.hostgator.com/~w57dsjmm/order/ducky/dispatch2.php");
}, 5000);
});
</script>
</head>
<body onLoad="init()">
<!-- header_eof //-->
<!-- body //-->
<!-- body_text //-->
<p><a href="http://order.southshorepizza.net/ducky">ADMIN</A>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Dispatch Screen</p>
<form action="dispatch_post.php" method="post">
<div class="dropdown" valign="center">
<select required name="dropdown">
<option value="Select Driver" selected>Select Driver</option>
<?php
$result = $db->Execute("SELECT * FROM " . TABLE_EMPLOYEES);
while (!$result->EOF) {
echo '<option value="' . $result->fields['employee_id'] . '">' . $result->fields['employee_first'] . '</option>';
$result->MoveNext();
}
?>
</select>
</div>
<table border="0" width="100%" cellspacing="0" cellpadding="2">
<tr class="dataTableHeadingRow">
<td class="dataTableHeadingContent" width="10%" align="center"><?php echo "Dispatch"; ?></td>
<td class="dataTableHeadingContent" width="20%" align="center"><?php echo TABLE_HEADING_ORDERS_ID; ?></td>
<td class="dataTableHeadingContent" width="30%" align="center"><?php echo "Address"; ?></td>
<td class="dataTableHeadingContent" width="20%" align="center"><?php echo "Order Age"; ?></td>
<td class="dataTableHeadingContent" width="20%" align="center"><?php echo TABLE_HEADING_ORDER_TOTAL; ?></td>
</tr>
</table>
<div id="div1">
</div>

<!--nwolybug added / to end the input -->
<input type="submit" />
</form>
</div>

dispatch2.php

<?php
/**
* @package admin
* @copyright Copyright 2003-2013 Zen Cart Development Team
* @copyright Portions Copyright 2003 osCommerce
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version GIT: $Id: Author: DrByte Wed Nov 6 21:04:33 2013 -0500 Modified in v1.5.2 $
*/

require('includes/application_top.php');

// unset variable which is sometimes tainted by bad plugins like magneticOne tools
if (isset($module)) unset($module);

require(DIR_WS_CLASSES . 'currencies.php');
$currencies = new currencies();

if (isset($_GET['oID'])) $_GET['oID'] = (int)$_GET['oID'];

include(DIR_WS_CLASSES . 'order.php');

?>


<!--nwolybug removed head and body tags, moved formatting to dispatch.php head -->

<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2">
<!-- body_text //-->
<tr>
<?php
$new_fields = ", o.delivery_street_address, o.shipping_module_code ";

$orders_query_raw = "select " . $search_distinct . " o.orders_id, o.customers_id, o.customers_name, o.payment_method, o.shipping_method, o.date_purchased, o.last_modified, o.currency, o.currency_value, s.orders_status_name, ot.text as order_total" .
$new_fields . "
from (" . TABLE_ORDERS_STATUS . " s, " .
TABLE_ORDERS . " o " .
$new_table . ")
left join " . TABLE_ORDERS_TOTAL . " ot on (o.orders_id = ot.orders_id and ot.class = 'ot_total') " . "
where (o.orders_status = s.orders_status_id and s.language_id = '" . (int)$_SESSION['languages_id'] . "' and o.shipping_module_code LIKE 'Flat' AND orders_status <> 3) " .
$search . " order by o.orders_id DESC";

//echo '<BR><BR>I SEE C: ' . $orders_query_raw . '<BR><BR>';

//last edit before $orders_query_raw }

// Split Page
// reset page when page is unknown
if (($_GET['page'] == '' or $_GET['page'] <= 1) and $_GET['oID'] != '') {
$check_page = $db->Execute($orders_query_raw);
$check_count=1;
if ($check_page->RecordCount() > '15') {
while (!$check_page->EOF) {
if ($check_page->fields['orders_id'] == $_GET['oID']) {
break;
}
$check_count++;
$check_page->MoveNext();
}
$_GET['page'] = round((($check_count/'15')+(fmod_round($check_count,'15') !=0 ? .5 : 0)),0);
} else {
$_GET['page'] = 1;
}
}

// $orders_query_numrows = '';
$orders_split = new splitPageResults($_GET['page'], '15', $orders_query_raw, $orders_query_numrows);
$orders = $db->Execute($orders_query_raw);
while (!$orders->EOF) {
if ((!isset($_GET['oID']) || (isset($_GET['oID']) && ($_GET['oID'] == $orders->fields['orders_id']))) && !isset($oInfo)) {
$oInfo = new objectInfo($orders->fields);
}


?>

<!--nwolybug changed div1 to div2 for naming standards. can't have two divs with same id name -->
<div id="div2">
<td class="dataTableContent" width="10%" align="center"><input type="checkbox" name="otd" value="$orders->fields['orders_id']" /></td>
<td class="dataTableContent" width="20%" align="center"><?php echo $show_difference . $orders->fields['orders_id']; ?></td>
<td class="dataTableContent" width="30%" align="center"><?php echo $orders->fields['delivery_street_address']; ?></td>
<td class="dataTableContent" width="20%" align="center"><?php
$purchase_time = strtotime ($orders->fields['date_purchased']);
$difference = time () - $purchase_time;
$difference_in_minutes = ceil ($difference / 60); //-Round up to the next minute
echo gmdate("H:i:s", $difference);
?></td>
<td class="dataTableContent" width="20%" align="center"><?php echo strip_tags($orders->fields['order_total']); ?></td></div>
</tr>
<?php
$orders->MoveNext();
}
?>
<tr>
<td class="smallText" valign="top" colspan="2"><?php echo $orders_split->display_count($orders_query_numrows, '15', $_GET['page'], TEXT_DISPLAY_NUMBER_OF_ORDERS); ?></td>
<td class="smallText" align="left"><?php echo $orders_split->display_links($orders_query_numrows, '15', MAX_DISPLAY_PAGE_LINKS, $_GET['page'], zen_get_all_get_params(array('page', 'oID', 'action'))); ?></td>
</tr>
</table>

dispatch_post.php

<?php
//nwolybug removed first of two <?php tags

global $db;
$otd = "otd";
$sql = "insert into " . TABLE_HTA . " (order_id, order_time, employee_id, otd, status) values (:$orders->fields['order_id']:, :$orders->fields['date_purchased']:, :$result->fields['employee_id']:, :$difference:, :'OTD':)";

$sql = $db->bindVars($sql, ':$orders->fields['order_id']:', $valueOne, 'integer');
$sql = $db->bindVars($sql, ':$orders->fields['date_purchased']:', $valueTwo, 'time');
$sql = $db->bindVars($sql, ':$result->fields['employee_id']:', $valueThree, 'integer');
$sql = $db->bindVars($sql, ':$difference:', $valueFour, 'time');
$sql = $db->bindVars($sql, ':$difference:', $valuefive, 'varchar');
$result = $db->Execute($sql);
$newRecordId = $db->Insert_ID();
echo 'The new record added was number: ' . $newRecordId;
?>

关于php - 提交表单时将变量传递到数据库时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25465433/

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