dsvbtgo639708 2018-01-04 03:35 采纳率: 0%
浏览 49
已采纳

php错误从文本区域获取值

Hey guys I'm having trouble capturing the value from my textarea in this form, I can read the first values of name and email but when the php code tries to read the Message of textarea it returns an error. Can someone please help me figure out what is wrong with my code? By the way I am still writing here since I need to fill up this space but this sentence is not really relevant to the question. Thanks!

HTML:

<form action="form_process.php" method="post">
      <div class="row">
        <div class="col-lg-6 text-center col-md-8 ml-auto mr-auto">
          <div class="input-group input-lg">
            <span class="input-group-addon">
              <i class="now-ui-icons users_circle-08"></i>
            </span>
            <input type="text" class="form-control" placeholder="First Name..." name="Name">
          </div>
          <div class="input-group input-lg">
            <span class="input-group-addon">
              <i class="now-ui-icons ui-1_email-85"></i>
            </span>
            <input type="text" class="form-control" placeholder="Email..." name="Email">
          </div>
          <form class="" action="form_process.php" method="post">
            <div class="textarea-container">
              <p>
                <textarea class="form-control" name="name" rows="4" cols="80" placeholder="Type a message..." name="MessageForMe"></textarea>
              </p>
            </div>
          </form>

          <div class="send-button">
            <input class="btn btn-primary btn-round btn-block btn-lg" type="submit" value="Submit" />
          </div>
        </div>
      </div>
    </form>

PHP:

<!DOCTYPE html>
<html>
<body>

<?php

$con = mysqli_connect("localhost","benji3pr","Benji3pr","Contact Form");

//if we dont connect
if(mysqli_connect_errno())
{
    echo "Failed to connect" . mysqli_connect_error();
}

//if we connect
if(mysqli_ping($con))
{
    echo "Connection Ok!!!";
}
else
{
    echo "Error: " . mysqli_error($con);
}

$name = $_POST['Name'];

$email = $_POST['Email'];

$message = $_POST['MessageForMe'];

echo (' ' . $name . ' ' . $email . ' ' . $message);

$sql = "INSERT INTO Contact Form (Name, Email, Message) VALUES ('$name', 
'$email', '$message')";

if (!mysqli_query($sql)){
  die('Error: ' . mysqli_error());
}



mysqli_close($con);

?>

</body>
</html>
  • 写回答

3条回答 默认 最新

  • duanliao2310 2018-01-04 03:46
    关注

    <form action="form_process.php" method="post">
        <div class="row">
            <div class="col-lg-6 text-center col-md-8 ml-auto mr-auto">
                <div class="input-group input-lg">
                    <span class="input-group-addon">
                        <i class="now-ui-icons users_circle-08"></i>
                    </span>
                    <input type="text" class="form-control" placeholder="First Name..." name="Name">
                </div>
                <div class="input-group input-lg">
                    <span class="input-group-addon">
                        <i class="now-ui-icons ui-1_email-85"></i>
                    </span>
                    <input type="text" class="form-control" placeholder="Email..." name="Email">
                </div>
                <div class="textarea-container">
                    <p>
                        <textarea class="form-control" rows="4" cols="80" placeholder="Type a message..." name="MessageForMe"></textarea>
                    </p>
                </div>
                <div class="send-button">
                    <input class="btn btn-primary btn-round btn-block btn-lg" type="submit" value="Submit" />
                </div>
            </div>
        </div>
    </form>

    You specified the name attribute twice on your . You had name="name" and name="MessageForMe" in the same textarea tag. This is probably why your code isn't working. Also, I noticed you wrapped your in a nested <form>, with the same action and method, which I don't believe is necessary.

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

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器