Home  >  Article  >  Backend Development  >  php error in getting form value

php error in getting form value

王林
王林Original
2019-09-27 11:58:072329browse

php error in getting form value

PHP error in getting form value

Error example:

<?php
$index = 1;
$filename = $_POST[&#39;filename&#39;];
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[&#39;filename&#39;])){
    $filename = $_POST[&#39;filename&#39;];
}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!

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