mysql - php无法获取表单数据

WBOY
Libérer: 2023-03-03 08:02:01
original
1435 Les gens l'ont consulté

1.wamp搭建的环境,用post获取表单提交数据返回值为空
代码如下:

<code>


    <meta charset="UTF-8">
    <title></title>


<form action="test.php" method="post">
    Firstname: <input type="text" name="firstname" value="aaa">
    Lastname: <input type="text" name="lastname">
    Age: <input type="text" name="age">
    <input type="submit">
</form>

</code>
Copier après la connexion
Copier après la connexion
<code><?PHP $firstname = $_POST["firstname"];
$lastname = $_POST["lastname"];
$age = $_POST["age"];
if($firstname==""){
  echo "<script>alert('Your username is empty!');";
}else{
  var_dump($firstname);
}
?></code>
Copier après la connexion
Copier après la connexion

报错:Notice: Undefined index: firstname in E:WebWeb SoftwarewampwwwDEMOtest.php

2.php服务器是阿帕奇没有错,端口号也是80没有错

3.试了get方法,依然得不到数据

mysql - php无法获取表单数据
mysql - php无法获取表单数据
mysql - php无法获取表单数据

我发现我自己的问题了:html文件没有从和php文件的同一路径打开~

回复内容:

1.wamp搭建的环境,用post获取表单提交数据返回值为空
代码如下:

<code>


    <meta charset="UTF-8">
    <title></title>


<form action="test.php" method="post">
    Firstname: <input type="text" name="firstname" value="aaa">
    Lastname: <input type="text" name="lastname">
    Age: <input type="text" name="age">
    <input type="submit">
</form>

</code>
Copier après la connexion
Copier après la connexion
<code><?PHP $firstname = $_POST["firstname"];
$lastname = $_POST["lastname"];
$age = $_POST["age"];
if($firstname==""){
  echo "<script>alert('Your username is empty!');";
}else{
  var_dump($firstname);
}
?></code>
Copier après la connexion
Copier après la connexion

报错:Notice: Undefined index: firstname in E:WebWeb SoftwarewampwwwDEMOtest.php

2.php服务器是阿帕奇没有错,端口号也是80没有错

3.试了get方法,依然得不到数据

mysql - php无法获取表单数据
mysql - php无法获取表单数据
mysql - php无法获取表单数据

我发现我自己的问题了:html文件没有从和php文件的同一路径打开~

确定几点问题!

1.本次测试的test1.htmltest.php两个文件均在同一级目录下DEMO
2.请不要使用file://路径访问你的PHP文件,这样PHP文件不会被安装在你电脑上的php.exe解释器解释。
3.请使用http://协议访问您的test1.html,并正确填入值提交表单到test.php
4.请注意你的PHP文件开头<?php 还是 <?PHP

确定好以上几点,看看问题是否还存在呢?

测试你的代码并没有问题
mysql - php无法获取表单数据

<code>Firstname: <input type="text" name="firstname" value="aaa">

改成

Firstname: <input type="text" name="firstname" value="aaa">

试试 name 和 value 之间少了一个空格吧</code>
Copier après la connexion

mysql - php无法获取表单数据

好像没问题啊?

报错:Notice: Undefined index: firstname in E:WebWeb SoftwarewampwwwDEMOtest.php

此错误是一个Notice级的错误,可以忽略,它是想告诉你$firstname还没有被申明就已经在使用了。但是如果不希望它出现,有很多办法。比如修改php.ini中的php_error。

Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!