Home  >  Article  >  Backend Development  >  一段关于浏览器传值出错的有关问题

一段关于浏览器传值出错的有关问题

WBOY
WBOYOriginal
2016-06-13 13:21:331030browse

一段关于浏览器传值出错的问题
这样写了两行代码,用来捕捉浏览器传值:

文件名:showclass.php

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
$p_class=$_GET[pclass];
echo $p_class;




然后输入网址:http://127.0.0.1/showclass.php?pclass=111
回车。

报错,内容如下:

Notice: Use of undefined constant pclass - assumed 'pclass' in D:\setup\xampp\htdocs\products\showclass.php on line 31
111 

如何才能不报错?
(用修改PHP.INI的来关闭notic的方法不算,因为要考虑代码可移植性。谢谢)

------解决方案--------------------
if(isset($_GET['pclass'])){
$pclass=$_GET['pclass'];
}else{
$pclass='';
}

var_dump($pclass);
------解决方案--------------------
pclass 加引号
------解决方案--------------------
这个也是必须的,很多初学者都很喜欢省略,其实是捡了芝麻,丢了西瓜.

探讨

pclass 加引号
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn