-1

I know a number of people have tried to answer this question but I have to ask because I have tried all the proposed solutions and none of them work for me. Whenever I attempt to test the PHP code it displays the error 'Cannot POST /contact.php'.

    <!DOCTYPE html>
    <html lang="en">

    <head>
      <meta charset="UTF-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
      <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
      <meta name="HandheldFriendly" content="true">
    </head>
    <body>
      <form action="contact.php" method="post">
        <div class="container-fluid contact-form">
          <div class="row centered content">
            <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 col-xl-6 b1">
              <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 b1">
                <input class="contact-info name" type="text" placeholder="Name" name="yourname" />
              </div>
              <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 b1">
                <input class="contact-info email" type="text" placeholder="Email" name="email" />
              </div>
              <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 b1">
                <input class="contact-info number" type="text" placeholder="Contact number" name="comments" />
              </div>
              <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 b1">
                <input class="contact-info subject" type="text" placeholder="Subject" name="subject" />
              </div>
            </div>

            <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 col-xl-6 b2">
              <textarea class="contact-message" name="comments" placeholder="Message" rows="10" cols="40"></textarea>


              <p class="how">How did you find out about 9haus?
                <select name="how">
    <option class="select" value=""> -- Please select -- </option>
    <option>Google search</option>
    <option>From a friend</option>
    <option>Link from a website</option>
    <option>9haus Publications</option>
    <option>Other</option>
    </select>
              </p>
            </div>
          </div>
          <div class="container-fluid contact-f">
            <div class="row centered">
              <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 b">
                <p><input class="send" type="submit" name="submit" value="Send"></p>
              </div>
            </div>
          </div>
        </div>
      </form>
    </div>
  </div>
 </body>
 </html>

And now the PHP code

<?php
/* Set e-mail recipient */
$myemail  = "review@studios.com";

/* Check all form inputs using check_input function */
$yourname = check_input($_POST['yourname'], "Enter your name");
$email    = check_input($_POST['email']);
$comments = check_input($_POST['comments'], "Write your comments");
$subject  = check_input($_POST['subject'], "Write a subject");
$how_find = check_input($_POST['how']);
$comments = check_input($_POST['comments'], "Write your comments");

/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
    show_error("Please enter valid email address");
}

/* If URL is not valid set $website to empty */
if (!preg_match("/^(https?:\/\/+[\w\-]+\.[\w\-]+)/i", $website))
{
    $website = '';
}

if(isset($_POST['submit'] && $human == '15')

else if(isset($_POST['submit'] && $human != '15')   

/* Let's prepare the message for the e-mail */
$message = "Hello!

Your request has been submitted to the 9haus graphics team:

Name: $yourname
E-mail: $email
URL: $website

How did he/she find it? $how_find

Comments:
$comments

End of message
";

/* Send the message using mail() function */
mail($myemail, $subject, $message);


/* Functions we used */
function check_input($data, $problem='')
{
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    if ($problem && strlen($data) == 0)
    {
        show_error($problem);
    }
    return $data;
}

function show_error($myError)
{
?>
    <html>
    <body>

    <b>Please correct the following error:</b><br />
    <?php echo $myError; ?>

    </body>
    </html>
<?php
exit();
}
?>

Any thoughts as to what I might be doing wrong?

Chid z
  • 1
  • 6
  • 1
    No `` tags..... no closing `` tag.. you've essentially got all the HTML in the head of the web page. – Scott Mar 05 '18 at 04:24
  • You have your entire from in `HEAD` tag? – Anand G Mar 05 '18 at 04:25
  • Oh sorry that was just a typo in the comments section. Now corrected – Chid z Mar 05 '18 at 04:27
  • okay.. is `contact.php` in the same directory as the HTML file? Are the file permissions for `contact.php` set correctly? – Scott Mar 05 '18 at 04:30
  • Yeah they're in the same folder. I don't know what you mean by file permissions. Just started using php. Please elaborate – Chid z Mar 05 '18 at 04:31
  • https://www.w3.org/Security/Faq/wwwsf3.html | https://www.digitalocean.com/community/questions/proper-permissions-for-web-server-s-directory | https://stackoverflow.com/questions/6846549/creating-writing-to-a-file-with-permission-755-from-php-fails-as-php-runs-as – Scott Mar 05 '18 at 04:34
  • What is this `col-xs-12 col-sm-12 col-md-6 col-lg-6 col-xl-6`? – hungrykoala Mar 05 '18 at 04:40
  • See if you get any more detailed error message by turning on [error reporting](https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display) – James Mar 05 '18 at 04:41
  • @hungrykoala its for some additional elements that were unnecessary to include for this. Does not affect the php code – Chid z Mar 05 '18 at 04:44
  • What I meant that why are you using bot xs and sm in the same class. I think you're using bootstrap wrongly here. – hungrykoala Mar 05 '18 at 04:46
  • @James no change – Chid z Mar 05 '18 at 04:47
  • @hungrykoala oh really? Alright I'll sort that swell. – Chid z Mar 05 '18 at 04:48

1 Answers1

0

After just checking your PHP code "contact.php" file, seems like there is syntax error coming on your if/else conditional statements. i.e

if(isset($_POST['submit'] && $human == '15')

else if(isset($_POST['submit'] && $human != '15') 

Try commenting these two statements, after then you will be able to POST to contact.php file.

Note: Here my only intension is to help you finding the root cause. You will then need to fix these conditional statements.

Hope it helps.

Jenis Patel
  • 1,617
  • 1
  • 13
  • 20