beginnerprogrammer
beginnerprogrammer

Reputation: 183

php file not being found

i am writing a unit converter php program. i have the set up of the page, but it seems like my php file is not being found. when i click the submit button i am brought a an error page. this is my html code.

<html>
<head>
</head>
<body>
<form action="hw7.php" method="post">
<h2>Convert length:</h2>
<p>Select conversion direction: <br />
<input type="radio" name="dir" value="1" 

checked="checked"/> Feet to meters<br />
<input type="radio" name="dir" value="2" /> Meters to feet<br 

/>
</p>

<p>Value to be converted: <br /><input type="text" 

name="cvalue" /></p>
<p><input type="submit" value="Convert" /></p>

 </form>
</body>
</html>

and here is my php file

<?php


$fTOm = $_POST["cvalue"] * 3.2808;
$mTOf = $_POST["cvalue"] / 3.2808;


echo "Result: ";
if ($POST[ 'dir'] == "1") <?php echo "$_POST["cvalue"]; ?> feet = <?php echo "fTOm"; ?> meters;


?>

Upvotes: 1

Views: 123

Answers (3)

PenguinCoder
PenguinCoder

Reputation: 4367

Your PHP script is likely causing a server error due to improper coding. Check your server logs for PHP related errors, and possibly turn on error_reporting for PHP.

Within your PHP script, you have a statement of:

if ($POST[ 'dir'] == "1") <?php echo "$_POST["cvalue"]; ?> feet = <?php echo "fTOm"; ?> meters;

Since you're already in a PHP script, why are you using the <?php echo inline an if statement?? Correct this issue and try running the script by directly calling it.

Change the if line to :

if ($POST[ 'dir'] == "1") {
  echo $_POST["cvalue"] . "feet , " .  $fTOm . " meters";

}

Upvotes: 1

Lukasz Bator
Lukasz Bator

Reputation: 141

try this maybe it will help:

<form action="./hw7.php" method="post">

Also remove all those syntax errors in the php script.<?php .... ... ?> can not have another <?php inside of it.

Upvotes: 1

Garis M Suero
Garis M Suero

Reputation: 8169

You should know that the hw7.php file must be in the same directory as the HTML page that is calling it from a form.

I will recommend to use always relative URLs or the contexT_path when possible.

try:

<form action="./hw7.php" method="post">

Upvotes: 1

Related Questions