-2

インターネット上で正常に動作するサーバーからローカル コンピューターにファイルを転送しました。

そして、それは私の変数に対して多くの未定義のインデックスをスローします。

インターネット上ではうまく機能し、ローカルでは機能しないため、何が問題なのか教えてください

以下はエラーと関連コードです

未定義のインデックス: /Users/mgltd/Sites/reacheasy/youraccount.php の 38 行目のコメント 警告: date(): システムのタイムゾーン設定に頼るのは安全ではありません。あなたはdate.timezone 設定または date_default_timezone_set() 関数を使用する必要があります。これらの方法のいずれかを使用してもこの警告が表示される場合は、タイムゾーン識別子のスペルが間違っている可能性があります。39 行目の /Users/mgltd/Sites/reacheasy/youraccount.php で、代わりに「BST/1.0/DST」に「Europe/London」を選択しました」

コード

<?php
    $submit = $_POST['Add'];
    //form data
    $Sname = mysql_real_escape_string(htmlentities(strip_tags($_POST['Sname'])));
    $Pname = mysql_real_escape_string(htmlentities(strip_tags($_POST['Pname'])));
    $Pidno = mysql_real_escape_string(htmlentities(strip_tags($_POST['Pidno'])));
    $Psize = mysql_real_escape_string(htmlentities(strip_tags($_POST['Psize'])));
    $Pcolour = mysql_real_escape_string(htmlentities(strip_tags($_POST['Pcolour'])));
    $Pquantity = $_POST['Pquantity'];
    $Weblink = mysql_real_escape_string(htmlentities(strip_tags($_POST['Weblink'])));
    $Price = mysql_real_escape_string(htmlentities(strip_tags($_POST['Price'])));
    $comment = mysql_real_escape_string(htmlentities(strip_tags($_POST['comment'])));
    $date = date("Y-m-d");
    //echo " ('','$Sname','$Pname','$Pidno','$Psize','$Pcolour','$Pquantity','$Weblink','$Price','$Uname')";
    if('POST' === $_SERVER['REQUEST_METHOD'])
    {
    if ($Sname&&$Pname&&$Pidno&&$Weblink&&$Price)
    {
    if (is_numeric($Price))
    {
        $repeatheck = mysql_query("SELECT * FROM repplac WHERE Uname = '{$_SESSION['username']}' AND Pidno ='$Pidno' AND Sname='$Sname' AND Pname='$Pname'");
        $count = mysql_num_rows($repeatheck);
    if($count!=0)
    {
        die ('PRODUCT ALREADY IN BASKET YOU CAN INCREASE OR DECREASE QUANTITY, <a href="youraccount.php">CLICK TO GO BACK TO YOUR LIST</a>');
    }
    else
    //echo'$Price';
    $tprice = $Price * $Pquantity;
    //echo"$tprice";
    $queryreg = mysql_query("
    INSERT INTO repplac VALUES ('','$Sname','$Pname','$Pidno','$Psize','$Pcolour','$Pquantity','$Weblink','$Price','$comment','$tprice','$date','{$_SESSION['username']}','')
    ")or die(mysql_error());
    }
    else
    echo 'price field requires numbers';
    }
    else
    echo 'please fill in all required * fields ';
    }
    ?>
    <form action='youraccount.php' method='Post' class='ilistbar'>
        <!--<div>
        <label for='shoppinglist' class='fixedwidth'></label>
        <textarea type='text' name='shoppinglist' id='username' cols='100' rows='15'></textarea>
        </div> -->
        <div>
        <label for='Sname' class='fixedwidth'> * Shop name</label>
        <input type='text' name='Sname' id='Sname'/>
        </div>
        <div>
        <label for='Pname' class='fixedwidth'> * Product name</label>
        <input type='text' name='Pname' id='Pname'/>
        </div>
        <div>
        <label for='Pidno' class='fixedwidth'> * Product id no /ad reference</label>
        <input type='text' name='Pidno' id='Pidno'/>
        (This should be unique for each product)
        </div>
        <div>
        <label for='Psize' class='fixedwidth'>Product size</label>
        <input type='text' name='Psize' id='Psize'/>
        </div>
        <div>
        <label for='Pcolour' class='fixedwidth'>Product colour</label>
        <input type='text' name='Pcolour' id='Pcolour'/>
        </div>
        <div>
        <label for='Pquantity' class='fixedwidth'>Product quantity</label>
        <select name="Pquantity" id="Pquantity">
         <option value="1">1</option>
         <option value="2">2</option>
         <option value="3">3</option>
         <option value="4">4</option>
         <option value="5">5</option>
         <option value="6">6</option>
         <option value="7">7</option>
         <option value="8">8</option>
         <option value="9">9</option>
         <option value="10">10</option>
    </select>
    (You can update quantity in excess of 10 on the shopping list below)
        </div>
        <div>
        <label for='Weblink' class='fixedwidth'> * Web link</label>
        <input type='text' name='Weblink' id='Weblink'/>
        </div>
        <div>
        <label for='Price' class='fixedwidth'> * Price GBP</label>
        <input type='text' name='Price' id='Price'/>
        Please valid format is (.) for decimal
        </div>
        <div>
        <label for='comment' class='fixedwidth'> Extra info</label>
        <input type='text' name='comment' id='comment'/>
        Please give different colours , sizes of the same products,discount codes, and other information that you would like us to use
        </div>
        <div>

        <div class='buttonarea'>
                <p>
                <input type='submit' name='submit' value='Add'>
                </p>
                </div>
                </p>
        </form>
4

2 に答える 2

3

if: の一番上にある php-block をラップします。

if( isset($_POST['submit']) ){ 

    // Rest of the code that populates the variables and so on

}

これにより、遠く離れた場所にさえない値を操作しようとしないことが保証されます。:)

于 2012-07-11T13:45:48.343 に答える
1

スーパーグローバルにデータが入力されていないよう$_POSTです (これを確認しましたか?)、または少なくとも、あなたが考えている機能が含まれていません。

あなたのコードは、チェックせずに POST 値を想定しているようです。

実行print_r($_POST)- 正しいデータが含まれているか?

于 2012-07-11T13:45:18.610 に答える