When using $ _POST
or $ _GET
to retrieve the variables from a form, you may encounter this error:
Notice: Undefined index 'fields of the table' in 'path of php file being executes' on line 'current line'
This error appears because of your PHP error reporting settings. Usually, it appears when your variable is not properly set. There are two ways to handle this issue:
1.Check if $_POST['action']
or $GET['action']
is set before using it. For example:
if (!isset($_POST['action'])) {//your pure stuff }
if (!isset($_GET['action'])) {//your pure stuff }
2. Suppress Notice warnings
Notice warnings could be suppressed by changing the error_reporting variable in your PHP.ini. error_reporting could be set to show all errors except those for notices and coding standards warnings: error_reporting = E_ALL & ~E_NOTICE
<?php error_reporting (E_ALL ^ E_NOTICE); ?>
but my personal suggestion is solve the warning instead of use the 2 method
updated question answer
you haven't add enclosing brackets {}
so the only one line after if will consider as in if body and your 2nd and 3rd echo will be executed whether the result of your if is true or false
it should be
if(isset($_POST['user_input']) && isset($_POST['search_for'])
&& isset($_POST['replace_with']) && !empty($_POST['user_input'])
&& !empty($_POST['search_for']) && !empty($_POST['replace_with'])) {
echo $user_input = $_POST['user_input'];
echo $search_for = $_POST['search_for'];
echo $replace_with = $_POST['replace_with'];
}