jeremiah123 2016-09-17 05:06 采纳率: 40%
浏览 3427
已采纳

php如何获取submit里面的值

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>

<body>

<body>
<form action="12321.php" method="get">
名字: <input type="text" name="fname"><br/>
年龄: <input type="text" name="age"><br/>
<input type="submit" value="提交" name="submit">
</form><br/>

<?php
$a=$_GET["fname"];
$b=$_GET["age"];
$c=$_POST[submit];
var_dump($c);
echo "</br>";
if(isset($c)){
 echo "欢迎".$a."</br>";
 echo "年龄".$b."</br>";
 }else
 {
 echo "欢迎光临";
 }
 ?> 
</body>
</html>

此文件的文件名是 12321.php
报错如下:
Notice: Undefined index: fname in F:\php\www\12321.php on line 18

Notice: Undefined index: age in F:\php\www\12321.php on line 19

Notice: Use of undefined constant submit - assumed 'submit' in F:\php\www\12321.php on line 20

Notice: Undefined index: submit in F:\php\www\12321.php on line 20

日志里面也不会记录错误,页面里面也不会报错

谢谢你们的帮助,$_POST改成$_REQUEST和$_GET, $c=$_REQUEST[“submit”];还是会提示一下错误

otice: Undefined index: fname in F:\php\www\12321.php on line 18

Notice: Undefined index: age in F:\php\www\12321.php on line 19

Notice: Undefined index: submit in F:\php\www\12321.php on line 20

错误的这几行内容
$a=$_GET["fname"];
$b=$_GET["age"];
$c=$_REQUEST[“submit”];

  • 写回答

4条回答

  • 泰 戈 尔 博客专家认证 2016-09-17 05:23
    关注
     $a=$_GET["fname"];
    $b=$_GET["age"];
    $c=$_POST[submit];
    

    第三行是什么鬼?你表单上明明写的get方式啊。要么用$_GET,要么用$_REQUEST。为什么要用$_POST呢?

    还有submit提交之后触发的是一个提交动作,本身并没有特定的值的。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler