Home > Backend Development > PHP Problem > php error in getting form value

php error in getting form value

王林
Release: 2023-02-25 09:22:01
Original
2388 people have browsed it

php error in getting form value

PHP error in getting form value

Error example:

<?php
$index = 1;
$filename = $_POST[&#39;filename&#39;];
echo $filename;
?>
Copy after login

$ _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; ?>">
Copy after login

Solution:

First method: isset judgment

if(isset($_POST[&#39;filename&#39;])){
    $filename = $_POST[&#39;filename&#39;];
}if(isset($filename)){ 
    echo $filename;
}
Copy after login

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
Copy after login

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; 
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template