Wrong HTML Page Loading from PHP

I can’t figure out, what went wrong with a site I’m working on. When you visit this page in progress, and type up some information and click submit the form is suppose to send you to a thank-you.html page, instead it’s loading up a completely wrong HTML page ?!?!?!?

The form tag’s action attribute is set to “/construction/construction_site_G.php” and that’s where it takes you!
What’s wrong with that?

I changed this and I checked all my files and I can’t find where to change it, you say it’s in the form tag but I can’t find it.

<form method="POST" name="contact_form" action="/construction/construction_site_G.php">

Currently line 592 of the final output of site_construction_a.htm

<form method=“POST” name=“contact_form” action=“<?php echo htmlentities($_SERVER[‘PHP_SELF’]); ?>”>

Wrong.

Well if you want it to go to thank_you.html (or whatever), then should that not be the action? Or if you have a PHP page processing the form, then you need to add a redirect in that page.

I changed it but the results are the same, arrrgghh this is driving me nuts. It was working and I don’t know what I did to screw it up.

This may be a dumb question, but do you know how forms work?

No, it appears that you are wrong. You’re submitting the data back to the same script that output the form to the browser. You have two methods of sending the visitor to a thankyou.html page after submission:

  1. The forms action tag - which has been pointed out to you and you claim the person is wrong because its sending back to the same script instead of thankyou.html

  2. A header redirect using header(‘Location: thankyou.html’). If this is the method you were using then the odds are you’ve output html or whitespace before the header() call. This will cause the header() call to become invalid and the rest of the script will continue to run instead.

Referring back to #1, is the form supposed to be processed in the same script? - Yes/No. I’m asking because if it is then you’re using the header() method for sure which makes it easier for us to diagnose.

Also having just visited your page you have raw php code showing up in the htm source code. PHP isn’t executing this code because if it was, it wouldn’t be output to the browser. It would be removed by php and only the html should be seen.

I did however find this in the code: header(‘Location: thank-you.html#Contact’);

So, you’re submitted the form back to the same page, to be processed by php code which cannot be executed because it has the wrong file extension. Change it to .php and it should run.

The weird thing is you’re code is all messed up and i don’t see how it could of ever worked. Your form is on site_construction_a.htm.

In your script you use:
<form method=“POST” name=“contact_form” action=“<?php echo htmlentities($_SERVER[‘PHP_SELF’]); ?>”>

Despite this, the form is submitted to construction_site_G.php - which isn’t the same name as the site_A.htm file. site_A.htm can’t execute as a php script anyway so i’m curious how you’re running php code to generate the action path in the first place because it should be exactly the same.

Next, your processing code is in site_A.htm but your still submitting to site_G.php.

It’s rather weird.

Well, PHP is not working, although this probably is an Apache server. When you post the data is posted to construction_site_G.php which is not present hence the error 404, hence no redirection to the thank you page.

Create a file called test.php and inside it enter the following:
<?php echo phpinfo(); ?>

View the file in a browser and see if PHP is running correctly.

Because it hasn’t been configured to work on .htm files. Regardless of it being apache (you sound like you dislike apache and are using this as an excuse to run it down) php will not work on any webserver if its not configured to do so properly. Apache is the best server for usage with php. The httpd.conf file needs updating to use php with .htm.

I solved it :slight_smile: I saw the error of my ways.

Except lines 595 & 599 which are displaying PHP code in the form boxes. I saw the error of my ways.

So what did you to then to fix it? - After getting so many of us involved it would be nice to know if any of us got it right :wink:

In all honestly no one got it right. One suggestion of the file extension PHP made me re-check the code and notice there was a path problem to which I was able to solve.

Fail :stuck_out_tongue:

You’re WRONG, FAIL :slight_smile: