我从我的服务器上传输了一个文件,该文件在互联网上正常运行到我的本地计算机。
它为我的变量抛出了很多未定义的索引,
请告诉我可能是什么问题,因为它在互联网上运行良好,而不是在本地工作
下面是错误和相关代码
“注意:未定义的索引:加入 /Users/mgltd/Sites/reacheasy/youraccount.php第27行注意: 未定义的索引:Sname in /Users/mgltd/Sites/reacheasy/youraccount.php 第30行注意:未定义的索引:Pname in 第31行/Users/mgltd/Sites/reacheasy/youraccount.php注意: 未定义索引:Pidno in /Users/mgltd/Sites/reacheasy/youraccount.php 第32行注意:未定义的索引:Psize in 第33行/Users/mgltd/Sites/reacheasy/youraccount.php注意: 未定义的索引:Pcolour in 第34行/Users/mgltd/Sites/reacheasy/youraccount.php注意: 未定义的索引:Pquantity in /Users/mgltd/Sites/reacheasy/youraccount.php第35行注意: 未定义的索引:Weblink in /Users/mgltd/Sites/reacheasy/youraccount.php第36行注意: 未定义的索引:/Users/mgltd/Sites/reacheasy/youraccount.php中的价格 第37行注意:未定义索引:注释 第38行/Users/mgltd/Sites/reacheasy/youraccount.php警告: date():依赖系统的时区设置是不安全的。您 必需使用date.timezone设置或 date_default_timezone_set()函数。如果您使用其中任何一个 方法,你最有可能仍然得到这个警告 拼写错误的时区标识符。我们选择了“欧洲/伦敦” 'BST / 1.0 / DST'改为/Users/mgltd/Sites/reacheasy/youraccount.php 在第39行“
代码
<?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>
答案 0 :(得分:3)
我会将php-block包装在if:
的顶部if( isset($_POST['submit']) ){
// Rest of the code that populates the variables and so on
}
这样可以确保您不会尝试操作远在那里的值。 :)
答案 1 :(得分:1)
看起来$_POST
超全球没有被填充(你有没有检查过这个?),或者至少它不包含你的想法。
您的代码似乎在没有检查的情况下假设POST值。
运行print_r($_POST)
- 它是否包含正确的数据?