Home>

We become indebted to.

I would like to create a flow that saves the data received in the form in phpmyadmin using an if statement and transitions to the next page with header (Location:'').

I want to save the data handled in the form to phpmyadmin, but I can't.
Therefore, it does not transition to the next page.

First of all, I want to be able to save the data in phpmyadmin.

// Processing when check is POSTed
    if ($_ POST ['check']) {
        // Save data in data and current time in created when able is POSTed
        if ($_ POST ['able']) {
            $date = $db->prepare ('INSERT INTO posts SET member_id = ?, data = ?, created = now ()');
            $data->execute (array (
            $mem ['id'],
            $_SESSION ['join'] ['able']
            ));

        }
        //// When wrong is POSTed
        if ($_ POST ['wrong']) {
            $date = $db->prepare ('INSERT INTO posts SET data = ?, created = now ()');
            $data->execute (array (
                $mem ['id'],
                $_SESSION ['wrong']
            ));
        }
        header ('Location: main.php');
        exit ();
    }
<form action = "" name = "check" method = "POST">
              <button type = "submit" name = "able" value = "<? php print (htmlspecialchars ($_POST ['able'], ENT_QUOTES));?>">Done</button>
              <button type = "submit" name = "wrong" value = "<? php print (htmlspecialchars ($_POST ['wrong'], ENT_QUOTES));?>">Failed</button>
          </form>

I would like to know if there is something wrong with the insert syntax or the description of foam.
Please lend me your wisdom. Thank you.

  • Answer # 1

    The name of the form may not be sent.
    It only sends the information of the input control "in" the form.
    If you really want to send name = check, use input type = hidden.

    Then debug.
    Put an echo before and after the branch of each if and "do you go through the expected place?"
    Var_dump the variable and "Is the expected value?"
    Put a try-catch and "Is there any abnormality in the action to DB?"

    In order to isolate the problem, it is better to disable redirect by header until all of the above are OK.

    Also, I think insert-set was a notation that can only be used with MySQL.

  • Answer # 2

    There is no wrong question mark and no number to enter.