dongtuo4132 2012-12-15 10:56
浏览 38

未定义的索引:第4行的C:\ wamp \ www \ emailvalidate.php中的电子邮件

I am new to Ajax. In my Ajax I get the following error message :

Notice: Undefined index: address in C:\wamp\www\test\sample.php on line 4

I googled but I didn't get a solution for my specified issue.

Here is what I did.

HTML Form with Ajax (test1.php)

<!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=utf-8" />
<title>Untitled Document</title>

<script>
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("mydiv").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("POST","test2.php",true);
xmlhttp.send();
}
</script>


</head>

<body>
<form id="form1" name="form1" method="post" action="test2.php">
  <p>
    <label for="address"></label>
    <input type="text" name="address" id="address" onblur="loadXMLDoc()"  />
    <input type="submit" name="submit" id="submit" value="Submit" />
  </p>
  <p><div id = 'mydiv'></div></p>
</form>
</body>
</html>

test2.php

 <!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=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<?php
echo "Your Address is ".$_POST['address'];
?>

</body>
</html>

I am sure it is very simple issue but I don't know how to solve it. Any help ?

  • 写回答

2条回答 默认 最新

  • dourangdz750379 2012-12-15 10:58
    关注

    You are not sending any input with a name of address

    I assume if you rename input name="mail"... to input name="address" some light will be shed on the situation.

    As an alternative solution... Change:

    <?php
    echo "Your Address is ".$_POST['address'];
    ?>
    

    to this

    <?php
    echo "Your Address is ".$_POST['mail'];
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用