Please help. Need this for school. Cant get PHP to work

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Please help. Need this for school. Cant get PHP to work

Postby n3xtgen » 12. March 2010 17:09

I just installed XAMPP and I think it is working fine. When I go to localhost the default welcome message comes up so I assume it is working, but I dont think the PHP is working. At school I need to write .html files that will send to PHP on submit so PHP can validate it. It works fine at school, but at home when I click on the submit button nothing happends, it does not go to PHP and display the message I want. Why is this?? I am using Windows 7. This is my code which works at school:

PHP File:
Code: Select all
<?php

$number1 = $_POST["number1"];
$number2 = $_POST["number2"];
$average = ($number1 + $number2)/2;

if($average>89)
{
print ("Average score: $average You got an A!<br>";
}

$max = $number1;

if($number1 < $number2)
{
$max = $number2;
}

print ("Your max score was $max");

?>



HTML File:
Code: Select all
<html>
<head>

<script language="javascript">

   function checkNumber()
   {
      if(document.form1.number1.value == "")
      {
         alert ("Please enter a number 1");
      }
      else if (document.form1.number2.value == 0)
      {
         alert("Please enter a second number");
      }
     
   }
</script>

<title>Excersise 10</title>
</head>

<body>
<form name="form1" method="post" action="" onSubmit="return checkNumber()" action="excercise10.php">
  <p>
    <label>
      Enter a number:
      <input type="text" name="number1" id="number1">
    </label>
  </p>
  <p>Enter a second number:
    <label>
      <input type="text" name="number2" id="number2">
    </label>
  </p>
  <p>
    <label>
      <input type="submit" name="submit" id="submit" value="Submit">
    </label>
  </p>
</form>
</body>
</html>



Please help. Thanks :)
n3xtgen
 
Posts: 2
Joined: 12. March 2010 17:01

Re: Please help. Need this for school. Cant get PHP to work

Postby Nobbie » 12. March 2010 17:50

I wonder that it runs in school, because its faulty HTML:

Code: Select all
<form name="form1" method="post" action="" onSubmit="return checkNumber()" action="excercise10.php">


The empy action-clause is wrong and you have to remove it. There is another action-clause in the end, but two actions are quite nonsense.

Also the onSubmit-Clause is very very ugly here and it is unpredictable, whether the action or the onSubmit has to be executed. How gave you this horrible code?
Nobbie
 
Posts: 8769
Joined: 09. March 2008 13:04

Re: Please help. Need this for school. Cant get PHP to work

Postby n3xtgen » 12. March 2010 19:09

opps, the second action is my mistake, must have added it in by mistake. :P

Works now :D

And also, what do yo mean that the onSubmit is very ugly/unpredictable? This is just sample code so we could see how PHP interacts with HTML.
n3xtgen
 
Posts: 2
Joined: 12. March 2010 17:01

Re: Please help. Need this for school. Cant get PHP to work

Postby wkelvinf » 14. March 2010 08:55

I believe he means the onSubmit should be an attribute of the input tag and not a form attribute

Code: Select all
<input type="submit" name="submit" id="submit" value="Submit" onSubmit="..." />
wkelvinf
 
Posts: 8
Joined: 13. March 2010 14:16

Re: Please help. Need this for school. Cant get PHP to work

Postby Nobbie » 14. March 2010 12:07

n3xtgen wrote:And also, what do yo mean that the onSubmit is very ugly/unpredictable?


Because you have TWO different ways of behaviour:

a) when you click submit and you have an action-Clause in the form, the "submitted" data is send to the webserver and the script of the action-Clause is executed and the output of the script is shown in your browser.

b) when you click submit and you have an onSubmit-Clause in form, the "submitted" data is send to your local JavaScript interpreter and the function of the onSubmit-Clause is executed and the output of the script is shown on your browser.

Question: what happens, if you have BOTH, the onSubmit and the action? Who wins? Who is first? And who is second and overrides the output of the first? Its unpredictable and nonsense. Its ugly and bad programming style. You must not use onSubmit and action in the same form.
Nobbie
 
Posts: 8769
Joined: 09. March 2008 13:04


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 69 guests