0

I am new to PHP and need to create a form. My form doesn't output the data I input into the form when I press submit. The files are being ran from the htdocs folder of my Apache server. Any help would be appreciated.

Here is my HTML code

 <html>
<body>

    <style>
      body {
        background-color: #66c2ff;
        font-family: 'Tangerine', serif;
        font-size: 24px;
      }
    </style>

        <div id="header" class="section">
            <p style="text-align:center;"> <img src="http://i63.tinypic.com/34sgvpy.png"> </p>
            <p align="center">Welcome</p>
        </div>


<form action="abiform.php" method="post">
<p>Company Name: <input type="text" name="yourname" /><br />
<br />
E-mail: <input type="text" name="email" /><br /></P>

<p>Urgency:
<input type="radio" name="urgency" value="Low" checked="checked" /> Low
<input type="radio" name="urgency" value="Medium" /> Medium
<input type="radio" name="urgency" value="High" /> High</p>

<p>Existing Feature or Issue:
<input type="radio" name="existingissue" value="Yes" checked="checked" /> Yes
<input type="radio" name="existingissue" value="No" /> No
<input type="radio" name="existingissue" value="Not Sure" /> Not Sure</p>

<p>Max Hours Willing to Spend on Issue: <input type="text" name="hours" /><br /></P>

<p>Issue Description:<br />
<textarea name="description" rows="10" cols="40"></textarea></p>

<p>Expected Outcome:<br />
<textarea name="outcome" rows="10" cols="40"></textarea></p>

<p><input type="submit" value="Submit"></p>
</form>

</body>
</html>

My PHP Form

<?php
$yourname = check_input($_POST['yourname']);
$email = check_input($_POST['email']);
$urgency = check_input($_POST['urgency']);
$existingissue = check_input($_POST['existingissue']);
$hours = check_input($_POST['hours']);
$description = check_input($_POST['description']);
$outcome = check_input($_POST['outcome']);
?>

<html>
<body>

Company Name: <?php echo $_POST['yourname']; ?><br />
<br />
Company e-mail: <?php echo $_POST['email']; ?><br />
<br />
Urgency: <?php echo $_POST['urgency']; ?><br />
<br />
Existing Feature or Issue? <?php echo $_POST['existingissue']; ?><br />
<br />
Max Hours Willing to Spend on Issue: <?php echo $_POST['hours']; ?><br />
<br />
Issue Description:<br />
<?php echo $_POST['description']; ?>
<br />
Expected Outcome:<br />
<?php echo $_POST['outcome']; ?>

</body>
</html>

<?php
function check_input($data)
{
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}
?>
K. Man
  • 1
  • 2
  • 1
    Can u show me the result now? – Ngo Tuan Jan 07 '18 at 07:40
  • @NgoTuan there is nothing that outputs. Here is a screenshot: https://screenshots.firefox.com/jH2UViEdIsFr6nLl/null – K. Man Jan 07 '18 at 16:35
  • @NgoTuan When I load the PHP file from localhost, I get these `undefined index errors`: https://screenshots.firefox.com/r96JENeOxhD3uBZu/localhost – K. Man Jan 07 '18 at 16:38
  • First the err when you load php file directly because $_post was undefined, no post request to it. – Ngo Tuan Jan 07 '18 at 16:44
  • @NgoTuan I'm sorry, I'm not following. Wouldn't `$_POST` work if I have defined the variables? If not, how would I correct for this error? thank you – K. Man Jan 07 '18 at 16:52
  • No definr variable does not matter. But i don't know why now. Is it console any error or when you dump$_post – Ngo Tuan Jan 07 '18 at 17:26
  • @NgoTuan should I add `if isset` before `$_POST`? – K. Man Jan 07 '18 at 17:52
  • No isset only help you to control flow your code, pre – Ngo Tuan Jan 07 '18 at 18:02
  • @NgoTuan have you tried running my code? Does it work for you? – K. Man Jan 07 '18 at 18:05
  • No isset only help you to control flow your code, prevent you from access variable that undefined. But in this case you know exacly your $_post is null. So we need to find out why. First dd($_post) for sure it null or not – Ngo Tuan Jan 07 '18 at 18:18
  • No, i'm now going on holidays so i don't have computer to run test – Ngo Tuan Jan 07 '18 at 18:20
  • @NgoTuan I had a friend run it on their computer and the code worked and outputted correctly. I have a Windows 10 OS. Do you think PHP is installed incorrectly or something? – K. Man Jan 07 '18 at 20:12

2 Answers2

0

Cause you are trying to check input before create, edit like this your php file.

<?php

function check_input($data)
{
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}

$yourname = check_input($_POST['yourname']);
$email = check_input($_POST['email']);
$urgency = check_input($_POST['urgency']);
$existingissue = check_input($_POST['existingissue']);
$hours = check_input($_POST['hours']);
$description = check_input($_POST['description']);
$outcome = check_input($_POST['outcome']);
?>

<html>
<body>

Company Name: <?php echo $_POST['yourname']; ?><br />
<br />
Company e-mail: <?php echo $_POST['email']; ?><br />
<br />
Urgency: <?php echo $_POST['urgency']; ?><br />
<br />
Existing Feature or Issue? <?php echo $_POST['existingissue']; ?><br />
<br />
Max Hours Willing to Spend on Issue: <?php echo $_POST['hours']; ?><br />
<br />
Issue Description:<br />
<?php echo $_POST['description']; ?>
<br />
Expected Outcome:<br />
<?php echo $_POST['outcome']; ?>

</body>
</html>
Eindex
  • 5
  • 3
  • Hi @Eindex, thanks for this. I tried it and it did **not** work. This is what happens, per usual: https://screenshots.firefox.com/jH2UViEdIsFr6nLl/null. When I load the PHP file from localhost, I get these `undefined index errors`: https://screenshots.firefox.com/r96JENeOxhD3uBZu/localhost – K. Man Jan 07 '18 at 16:38
0

The issue was with localhost. The solution was in this thread: PHP code is not being executed, instead code shows on the page. It was an https issue where I had to open the HTML file using localhost with https

K. Man
  • 1
  • 2