dsvbtgo639708
dsvbtgo639708
2018-01-04 03:35
浏览 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
    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>
    
    点赞 评论
  • doujiao6116
    doujiao6116 2018-01-04 03:40

    Remove the name="name" attribute from your textarea :

    <textarea class="form-control" name="name" rows="4" cols="80" placeholder="Type a message..." name="MessageForMe"></textarea>
    

    to :

    <textarea class="form-control" rows="4" cols="80" placeholder="Type a message..." name="MessageForMe"></textarea>
    
    点赞 评论
  • dqfsbvd43312
    dqfsbvd43312 2018-01-04 03:47

    You are using name attribute twice in the textArea field. Remove name="name" and change it to the following. It should work now.

    <textarea class="form-control" rows="4" cols="80" placeholder="Type a message..." name="MessageForMe"></textarea>
    
    点赞 评论

相关推荐