Javascript 注意:未定义索引:

Javascript 注意:未定义索引:,javascript,php,html,Javascript,Php,Html,我遇到以下错误: Notice: Undefined index: oid in C:\wamp\www\var\de\products.php on line 9 Warning: Invalid argument supplied for foreach() in C:\wamp\www\var\de\products.php on line 45 有谁能指导我如何解决这个问题: <?php include('all.php'); include('product.php');

我遇到以下错误:

Notice: Undefined index: oid in C:\wamp\www\var\de\products.php on line 9

Warning: Invalid argument supplied for foreach() in C:\wamp\www\var\de\products.php on line 45
有谁能指导我如何解决这个问题:

<?php

include('all.php');
include('product.php');

$product = new Products();


$order_details = $product->loadOrderDetails(intval($_GET['oid']));

print $order_details;

?>
<html>
<head>
    <title>Debug Test</title>

</head>
<body>


    <br/>

    <table align="center" border="1" cellpadding="1" cellspacing="2" width="90%">
        <tr>
            <th>Order id</th>
            <th>Order Date</th>
            <th colspan="2">Order Total</th>
        </tr>
        <tr>
            <td><?=$order_details['order_id'];?></td>
            <td><?=$order_details['ordered_on'];?></td>
            <td colspan="2"><?=$order_details['order_total'];?></td>
        </tr>
        <tr>
            <td colspan="5">&nbsp;</td>
        </tr>
        <tr>
            <th>Name</th>
            <th>Description</th>
            <th>Price</th>
            <th>Qty</th>
        </tr>
<?php
    foreach ($order_details['products'] as $pid => $info) {
?>
        <tr>
            <td><?=$info['name'];?></td>
            <td><?=$info['description'];?></td>
            <td><?=$info['price'];?></td>
            <td><?=$info['qty'];?></td>
        </tr>
<?php
    }
?>
        <tr>
            <td colspan="5">&nbsp;</td>
        </tr>
        <tr>
            <th colspan="5">Customer Information</th>
        </tr>
        <tr>
            <td colspan="5">
                <?=$order_details['customer_info']['username'];?><br/>
                <?=$order_details['customer_info']['company_name'];?><br/>
                <?=$order_details['address']['street'];?><br/>
                <?=$order_details['address']['city'].', '.$order_details['address']['state'].' '.$order_details['address']['zip'];?><br/>
            </td>
        </tr>
    </table>

</body>
</html>

除错测试

订单号 订购日期 订单总数 名称 描述 价格 数量 客户信息



all.php

<?php

/**
 * Fake database access
 * @return array customer info
 */
function getCustomerInfo() {

    return array (
        1=>array(
            'customer_id' => 1,
            'username'=>'george',
            'address_id' => 3,
            'created_on'=>'2005-01-28',
            'company_name'=>'Foo Inc.',
        ),
        2=>array(
            'customer_id' => 2,
            'username'=>'sam',
            'address_id' => 2,
            'created_on'=>'2005-10-09',
            'company_name'=>'Foo Inc.',
        ),
        3=>array(
            'customer_id' => 3,
            'username'=>'harrison',
            'address_id' => 1,
            'created_on'=>'2005-07-21',
            'company_name'=>'Bar Inc.',
        )
    );
}

function getAddresses() {
    return array(
        1 => array(
            'address_id' => 1,
            'street' => '123 Main St.',
            'city' => 'Some City',
            'state' => 'PA',
            'zip' => '12345'),
        2 => array(
            'address_id' => 2,
            'street' => '345 Garden Dr.',
            'city' => 'Manhatten',
            'state' => 'NY',
            'zip' => '55555'),
        3 => array(
            'address_id' => 3,
            'street' => '876 Over There BLVD',
            'city' => 'Atlanta',
            'state' => 'GA',
            'zip' => '88899'));
}

/**
 * Fake database access
 * @return array customer info
 */
function getOrderInfo() {
    return array (
        1=>array(
            'order_id' => 1,
            'ordered_on'=>'2006-11-17',
            'ordered_by'=>1,
            'order_total' => '47.00',
            'products'=>array(
            array('product_id' => 5, 'qty' => 2),
            array('product_id' => 6, 'qty' => 1),
            array('product_id' => 7, 'qty' => 3))
        ),

        2=>array(
            'order_id' => 2,
            'ordered_on'=>'2006-10-17',
            'ordered_by'=>1,
            'order_total' => '4.00',
            'products'=>array(
            array('product_id' => 1, 'qty' => 3),
            array('product_id' => 2, 'qty' => 1),
            array('product_id' => 7, 'qty' => 2))
        ),

        3=>array(
            'order_id' => 3,
            'ordered_on'=>'2006-11-12',
            'ordered_by'=>3,
            'order_total' => '43.00',
            'products'=>array(
            array('product_id' => 5, 'qty' => 1),
            array('product_id' => 6, 'qty' => 2))
        )
    );
}


/**
 * Fake database access
 * @return array customer info
 */
function getProducts() {
    return array (
        1=>array(
            'product_id' => 1,
            'name'=>'Product A',
            'description'=>'Fancy Product with options',
            'price' => '10.00',
        ),
        2=>array(
            'product_id' => 2,
            'name'=>'Product B',
            'description'=>'Fancy Product with options',
            'price' => '10.00',
        ),
        3=>array(
            'product_id' => 3,
            'name'=>'Product C',
            'description'=>'Fancy Product with options',
            'price' => '20.00',
        ),
        4=>array(
            'product_id' => 4,
            'name'=>'Product D',
            'description'=>'Fancy Product with options',
            'price' => '5.00',
        ),
        5=>array(
            'product_id' => 5,
            'name'=>'Product E',
            'description'=>'Fancy Product with options',
            'price' => '13.00',
        ),
        6=>array(
            'product_id' => 6,
            'name'=>'Product F',
            'description'=>'Fancy Product with options',
            'price' => '15.00',
        ),
        7=>array(
            'product_id' => 7,
            'name'=>'Product G',
            'description'=>'Fancy Product with options',
            'price' => '2.00',
        )
    );
}

function print_array($a) {
    echo '<pre>';
    print_r($a);
    echo '</pre>';
}


?>

Product.php

$order_details = $product->loadOrderDetails(intval($_GET['oid']));

所讨论的数组是
$\u GET[]
。。。也就是说

您是否使用该变量调用您的文件?什么样的


因为这就是它所寻找的-看起来所有其他错误都是此错误的级联后果。

所讨论的数组是
$\u GET[]
。。。也就是说

您是否使用该变量调用您的文件?什么样的


因为这就是它所寻找的-看起来所有其他错误都是此错误的级联结果。

错误来自此行,其原因是您试图访问未设置的变量

if(!empty($_GET['oid'])) {
    $order_details = $product->loadOrderDetails(intval($_GET['oid']));
}
通过URL传递GET参数,如
products.php?oid=123
,如果不将其添加到URL,则会出现此错误。因此,我建议您更改代码,在使用变量之前检查变量是否已设置。差不多


您的第二个错误与第一个错误有关。因为
$\u GET['oid']
不存在,这意味着
$order\u details
可能是空的。因此,在执行
foreach
之前,您还需要进一步检查代码,以检查$order\u details是否为空

错误来自此行及其原因,因为您试图访问未设置的变量

if(!empty($_GET['oid'])) {
    $order_details = $product->loadOrderDetails(intval($_GET['oid']));
}
通过URL传递GET参数,如
products.php?oid=123
,如果不将其添加到URL,则会出现此错误。因此,我建议您更改代码,在使用变量之前检查变量是否已设置。差不多


您的第二个错误与第一个错误有关。因为
$\u GET['oid']
不存在,这意味着
$order\u details
可能是空的。因此,在执行
foreach
之前,您还需要进一步检查代码,以检查$order\u details是否为空

您正在尝试未设置的读取字段。Perphaps当调用脚本时,如果没有
oid
参数,例如
products.php?oid=12345
,就会发生这种情况。因此,不要认为您在
$\u GET['oid']
中设置了值,请检查它是否已设置,例如,使用
isset($\u GET['oid'])
并基于此,您可以决定是否尝试加载产品等。

您正在尝试未设置的读取字段。Perphaps当调用脚本时,如果没有
oid
参数,例如
products.php?oid=12345
,就会发生这种情况。因此,不要认为您在
$\u GET['oid']
中设置了值,请检查是否设置了值,例如,使用
isset($\u GET['oid'])
,并基于此,您可以决定是否尝试加载产品等。

带名称的输入在哪里?带名称的输入在哪里?