开发者

Illegal array-declaration in PHP?

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] = 开发者_Go百科$stuff3;
  ?>   


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.


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.


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).


Try var_dump($_POST)

or a bit of validation

if (isset() && !empty($_POST["stuff1")) {
    $myStuff[0] = $_POST["stuff1"];
} else {
    echo '$_POST["stuff1"] error';
}

Check everything is being sent across correctly...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜