-3

Why doesn't this validate with the W3C validator:

3 variables from form.html going into form.php:

  <?php

   $stuff1 = $_POST["stuff1"];//catch variables
   $stuff2 = $_POST["stuff2"]; 
   $stuff3 = $_POST["stuff3"]; 
   $myStuff[0] = $stuff1;//put into array
   $myStuff[1] = $stuff2;
   $myStuff[2] = $stuff3;
  ?>   
3
  • i think you might need key and a value, The post variable is array itself.. Commented Feb 10, 2010 at 9:55
  • 5
    The W3C (html) validator is not supposed to see any php source code, only the output of your script. Since the code snippet you've provided doesn't print anything the validator should see ...nothing. a) post the original error message(s) b) provide the code that is responsible for the output. Commented Feb 10, 2010 at 9:57
  • Oh of course your'e right a certain difference.. there but the problem is with the print_r($myStuff) later on Commented Feb 10, 2010 at 10:19

3 Answers 3

7

Why doesn't this validate with the W3C validator:

You may be misunderstanding something here. PHP code is generated on the server side, and outputs HTML (or not). Your abovementioned script will not pass any HTML validator, because to the validator, it will be empty. PHP and the W3C validator have nothing to do with each other.

If you are getting a PHP error message, please post it.

Sign up to request clarification or add additional context in comments.

1 Comment

+1 - I think understanding that difference is probably more useful to the OP than dealing with what is wrong with his code; and for use of the word "abovementioned" (dictionary.reference.com/browse/abovementioned, for you doubters).
0

It seems to be fine but try this too:

 $stuff1 = $_POST["stuff1"];
 $stuff2 = $_POST["stuff2"]; 
 $stuff3 = $_POST["stuff3"]; 

 $myarray = array();
 $myarray[] = $stuff1;
 $myarray[] = $stuff2;
 $myarray[] = $stuff3;

 print_r($myarray);

Also make sure that you put your fields inside a form eg form tag.

Note that php code is not something to be validated by the W3C validator, it is server-side generated code.

1 Comment

Yes your all correct with the difference some mistakes one make..., thanks!
0

Try declaring your array:

$stuff1 = $_POST["stuff1"];//catch variables
$stuff2 = $_POST["stuff2"]; 
$stuff3 = $_POST["stuff3"]; 
$myStuff = array();
$myStuff[0] = $stuff1;//put into array
$myStuff[1] = $stuff2;
$myStuff[2] = $stuff3;

and note Pekka's answer about the difference between PHP (server-side) and HTML (client-side).

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.