PHP error in getting form value
Error example:
<?php $index = 1; $filename = $_POST['filename']; echo $filename; ?>
$ _POST ['filename '] From another page:
<?php $db = substr($string[0],14) . "_" . substr($string[1],14) . "_db.txt"; ?> <input type="hidden" name="filename" value="<?php echo $db; ?>">
Solution:
First method: isset judgment
if(isset($_POST['filename'])){ $filename = $_POST['filename']; }if(isset($filename)){ echo $filename; }
Second method: Shield warning
Modify the error display mode under the error configuration in php.ini: Modify error_reporting = E_ALL to
error_reporting = E_ALL & ~E_NOTICE
Restart after modification Download the APCHE server to take effect.
Third method: Custom function
function _get($str){ $val = isset($_GET[$str]) ? $_GET[$str] : null; return $val; }
Pass the value through this function.
The fourth method: @
Add @ before the notice code. @ indicates that there is an error in this line or a warning not to output, @username=_post[ 'username'];
Recommended tutorial: PHP video tutorial
The above is the detailed content of php error in getting form value. For more information, please follow other related articles on the PHP Chinese website!