1

I am trying to collect data from text boxes, radials, checkboxes, etc and then display them with my display_results.php. However I keep encountering a nagging problem error undefined index but I thought I did define the index with my variable $num. I have not been instructed to use isset() function only $_POST since the form uses the form POST method. Could someone please point out why the variable isn't being indexed and displayed without isset()?

Thanks for any help!

<?php
// get the data from the form
$email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);

// get the rest of the data for the form
$password = filter_input(INPUT_POST, 'password');

$num = filter_input(INPUT_POST, 'num');

$heard_from = filter_input(INPUT_POST, 'heard_from' ); ?>

<!DOCTYPE html>
<html>
<head>
    <title>Account Information</title>
    <link rel="stylesheet" type="text/css" href="main.css"/>
</head>
<body>
    <main>
        <h1>Account Information</h1>

        <label>Email Address:</label>
        <span><?php echo htmlspecialchars($email); ?></span><br>

        <label>Password:</label>
        <span><?php echo $_POST['password']?></span><br>

        <label>Phone Number:</label>
        <span><?php echo $_POST['num']?></span><br>

        <label>Heard From:</label>
        <span><?php echo $_POST['heard_from']?></span><br>
      
    </main>
</body>
</html>
  • I was asked to code with what we have learned so far and the isset() function has not yet been covered. So the previously answered question is helpful for personal knowledge but not entirely applicable to my situation at the moment. Thank you for the good link however. –  Oct 12 '16 at 21:49

1 Answers1

0

I assume you've got 3 or more pages (form, 1st snippet, 2nd snippet) and you're passing the data from the first snippet to your second snippet, in which you're echoing the raw POST data

echo $_POST['num']

but you should be echoing your filtered input vars

echo $num
Jeff Puckett
  • 37,464
  • 17
  • 118
  • 167