这几天在看所谓的圣经PHP和MySQL_Web开发,结果第一个例子就出问题了:
Bob's Auto Parts
Order Results
Order processed at 11:55, 19th March
Your order is as follows:
Notice: Undefined variable: tireqty in \xampp\htdocs\c1\processorder.php on line 14
tires
Notice: Undefined variable: oilqty in \xampp\htdocs\c1\processorder.php on line 15
bottles of oil
Notice: Undefined variable: sparkqty in \xampp\htdocs\c1\processorder.php on line 16
spark plugs
Notice: Undefined variable: oilqty in \xampp\htdocs\c1\processorder.php on line 22
Notice: Undefined variable: tireqty in \xampp\htdocs\c1\processorder.php on line 22
Notice: Undefined variable: sparkqty in \xampp\htdocs\c1\processorder.php on line 22
Items ordered: 0
真叫人抓狂,于是谷歌之,挑了几个中文网页看看。喝,里面的人都要去改php.ini,把Notice干掉,这不是掩耳盗铃么,这相当于得了病自己把自己眼睛戳瞎。
看了还是几个老外说得对头,这本圣经已经是好多年前的古董了,很多语法现在都变得不规范了。老外是这么说的:
this is not the main issue tho. the book is using old php code. php doesnt work like this anymore.. when you send a varible using POST from one file to another you need to collect it in the second file
you do this by using
$tireqty=$_POST['tireqty'];
so add this code to the top of your process file before anything
<?php
$tireqty =$_POST['tireqty'];
$oilqty =$_POST['oilqty'];
$sparkqty =$_POST['sparkqty'];
$find =$_POST['find'];
?>
改好之后就是这个效果了:
知识共享署名-非商业性使用-相同方式共享:码农场 » Notice: Undefined variable: tireqty 解决
原来少了一行$find=$_POST[‘find’]; 解决了