Home>

Roughly speaking, I am making a program that inputs keywords in the search form, extracts information from the database, and displays it on the result screen. What I want to do is to install a button to update the contents of the database on the result screen and update it normally. However, when I installed a button to move to the same page and clicked the button,Notice: Undefined indexIt will come out.

The probable cause is that you jumped directly to the result screen without going through the input screen, but if you try rewriting the contents of the database and pressing the update button, the contents will be rewritten according to the first entered word. Since the contents have changed properly, it seems that the post data was automatically retransmitted. However, I'm not sure because I thought it was an error that occurred when the entered information was empty.

How can I hide this error?

Corresponding source code
//Search screen
<form method = "post" action = "kekka.php">
<input type = "text" name = "aa">
<input type = "submit" value = "search button">
</form>

// Result screen
<? php
** ~ Database password information ~ **
$name = $_POST ['aa'];
** ~ Select statement that displays the contents of the database based on the searched word ~ **
?>
<head>
<meta charset = "utf-8">
<title>select</title>
</head>
<body>
-Button to refresh the screen (act on the same page)-
** ~ Output part ~ **
</body>
</html>
php
  • Answer # 1

    For the time being, please consider branching by REQUEST_METHOD of $_SERVER.
    Also use filter_input.

    The rest depends on what kind of configuration you are trying to operate the function.
    In some cases, ajax is also an effective method. In some cases.

  • Answer # 2

    Processing when receiving $_GET, $_POST, etc. --Qiita has an article that summarizes the basic idea to some extent.

    for your information.

  • Answer # 3

    I was able to solve it by using a php session.
    Thanks to takasima20 for giving me the word "hold".
    Thank you everyone for your answers!