在调试一个程序的时候发现很奇怪的现象,post传过来的值再某些地方为空,先看下面的代码 1 ? php 2 if ( $_POST ['submit'] == 'Add' ){ 3 if ( $_POST ['type']='movie' $_POST ['movie_type'] == '' ){ 4 header ('Location:form4.php' ); 5 } 6 } 7 ? 8 h
在调试一个程序的时候发现很奇怪的现象,post传过来的值再某些地方为空,先看下面的代码
<span> 1</span> <span>php </span><span> 2</span> <span>if</span>(<span>$_POST</span>['submit'] == 'Add'<span>){ </span><span> 3</span> <span>if</span>(<span>$_POST</span>['type']='movie' && <span>$_POST</span>['movie_type'] == ''<span>){ </span><span> 4</span> <span>header</span>('Location:form4.php'<span>); </span><span> 5</span> <span> } </span><span> 6</span> <span>} </span><span> 7</span> ?> <span> 8</span> <span> 9</span> <span>10</span> <title>Multipurpose Form</title> <span>11</span> <span>12</span> <span>13</span> <span>php </span><span>14</span> <span>15</span> <span>if</span>(<span>$_POST</span>['submit'] == 'Add'<span>){ </span><span>16</span> <span>echo</span> '<h1>Add '.<span>ucfirst</span>(<span>$_POST</span>['type']).'</h1>'<span>; </span><span>17</span> ?> <span>18</span>
Searching for '.$_POST["name"].'...
'; 61 } 62 63 if(isset($_POST['debug'])){ 64 echo ''<span>; </span><span>65</span> <span>print_r</span>(<span>$_POST</span><span>); </span><span>66</span> <span>echo</span> '
在第29行是要根据上一个页面传递过来的值来输出信息的,但是即使传递过来的值是movie,还是没有输出想要的值,我我在很多地方都添加了echo($_POST['type']);这一句话发先在代码最顶端还能输出movie 的,第二行下面还是能够输出,就是在第三行下面就没有值了,这里你可能也发现错误了,if($_POST['type']='movie',这一句,本来是判断语句,结果少写了一个等号变成了赋值语句,初学者错误啊!!!!!!
正确的写法应该是if($_POST['type']=='movie' && $_POST['movie_type'] == '')
<br><br>