php中常见小问题 Notice: Undefined index: width
来源:互联网 发布:机器人专业和人工智能 编辑:程序博客网 时间:2024/06/07 00:06
在编写类中小方法的时候
private function getRect(){ $input='<b>请输入 | 矩形 | 的宽度和高度:</br>'; $input.='宽度: <input type="text" name="width" value="'.$_POST['width'].'"> <br>'; $input.='高度: <input type="text" name="height" value="'.$_POST['height'].'"> <br>'; return $input;}
其中的部分是为了将页面点提交之后输入框中仍然可以保留输入值,但是这样编写,运行之后会出现报错
Notice: Undefined index: width in G:\php\htdocs\xsphp\shape\form.class.php on line42
Notice: Undefined index: height in G:\php\htdocs\xsphp\shape\form.class.php on line43
这两行报错意思是说width 和height 没有被定义,由于刚刚开始运行程序,没有输入值,所以对程序而言是没有定义这两个变量,所以有些服务器对于这种情况便会报错
所以增加语句进行判断该变量是否存在,如果不存在就定义为空
private function getRect(){ $input='<b>请输入 | 矩形 | 的宽度和高度:</br>'; $input.='宽度: <input type="text" name="width" value="'.(isset($_POST['width'])? $_POST['width']: "").'"> <br>'; $input.='高度: <input type="text" name="height" value="'.(isset($_POST['height'])? $_POST['height']: "").'"> <br>'; return $input;}
对于类似问题就可以这么进行判断处理
0 0
- php中常见小问题 Notice: Undefined index: width
- PHP Notice: Undefined index:
- PHP Notice: Undefined index: ... 问题的解决方案
- PHP Notice: Undefined index: ... 问题的解决方案
- PHP Notice: Undefined index: ... 问题的解决方案
- PHP Notice: Undefined index: ... 问题的解决方法
- PHP Notice: Undefined index: ... 问题的解决方案
- PHP Notice: Undefined index: ... 问题的解决方法:
- PHP Notice: Undefined index: ... 问题的解决方法:
- PHP Notice: Undefined index: ... 问题的解决方法:
- PHP Notice: Undefined index: ... 问题的解决方法:
- PHP Notice: Undefined index: ... 问题的解决方案
- php 中 Notice:undefined index 解决方法
- PHP Notice: Undefined index和Undefined variable问题的解决方法:
- php 解决Notice: Undefined index:
- PHP Notice: undefined index 解决方法
- PHP中出现Notice: Undefined index的三种解决办法
- PHP中出现Notice: Undefined index的三种解决办法
- 正值表达式匹配中文
- 从0自学C#09--抽象工厂模式实例
- JavaScript中的map()
- 分模块创建maven项目和之间的关系管理
- DHCP工作原理
- php中常见小问题 Notice: Undefined index: width
- java中解析xml时的“伪属性名称”
- 《Android和PHP最佳实践》官方站
- Linux进程间通信的几种方式总结--linux内核剖析(七)
- source insight代码格式化(Astyle)
- 登录cloudera manager,并查询impala query历史java示例
- AndroidStudio快捷键总结
- hadoop学习WordCount+Block+Split+Shuffle+MapReduce详解
- Android的布局Layout