douhuzhi0907 2014-04-24 13:25
浏览 53
已采纳

PHP表单错误,新手[重复]

This question already has an answer here:

Hi guys having little problem with a form....when publish to site I get this error (Notice: Undefined index:), it works but just error above actual form, singled out the top part of the form below where its saying where error is......

<?php
$action=$_REQUEST['action'];
if ($action=="")    /* display the contact form */
{
?>



<?php
$action=$_REQUEST['action'];
if ($action=="")    /* display the contact form */
{
?>
<form  action="" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
Your name:<br>
<input name="name" type="text" value="" size="30"/><br>
Your email:<br>
<input name="email" type="text" value="" size="30"/><br>
Your message:<br>
<textarea name="message" rows="7" cols="30"></textarea><br>
<input type="submit" value="Send email"/>
</form>
<?php
} 
else                /* send the submitted data */
{
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$message=$_REQUEST['message'];
if (($name=="")||($email=="")||($message==""))
    {
    echo "All fields are required, please fill <a href=\"\">the form</a> again.";
    }
else{        
    $from="From: $name<$email>
Return-path: $email";
    $subject="Message sent using your contact form";
    mail("myemail@email.com", $subject, $message, $from);
    echo "Email sent!";
    }
}  
?>
</div>
  • 写回答

5条回答 默认 最新

  • drws65968272 2014-04-24 13:43
    关注

    Change your code with this... you should use empty function in php to check variabel is empty or not. because index action in $_REQUEST['action'] is never exist when the first code is running.

    <?php
    $action = (!empty($_REQUEST['action'])) ? $_REQUEST['action'] : "";
    if ($action==""):  /* display the contact form */
    ?>
    
    
    
    <?php
    $action= (!empty($_REQUEST['action'])) ? $_REQUEST['action'] : "";
    if ($action==""):    /* display the contact form */
    ?>
    <form  action="" method="POST" enctype="multipart/form-data">
    <input type="hidden" name="action" value="submit">
    Your name:<br>
    <input name="name" type="text" value="" size="30"/><br>
    Your email:<br>
    <input name="email" type="text" value="" size="30"/><br>
    Your message:<br>
    <textarea name="message" rows="7" cols="30"></textarea><br>
    <input type="submit" value="Send email"/>
    </form>
    <?php
    endif;
    else:                /* send the submitted data */
    $name=$_REQUEST['name'];
    $email=$_REQUEST['email'];
    $message=$_REQUEST['message'];
    
    if (($name=="")||($email=="")||($message==""))
        {
        echo "All fields are required, please fill <a href=\"\">the form</a> again.";
        }
    else{        
        $from="From: $name<$email>
    Return-path: $email";
        $subject="Message sent using your contact form";
        mail("aridjemana@email.com", $subject, $message, $from);
        echo "Email sent!";
        }
    endif;
    ?> 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大