drj58429 2017-09-14 03:06
浏览 46

HTML表单Textarea。 使用PHP将数据发送到MySQL。 注意:未定义的索引

I was trying to send data from my Form to My data base, but i keep on having the same error at the Textarea part.

I am not sure whether i has to do with data type in MYSQL, but i tried that also by setting it to text, medium, text, long text and etc.

The connection is successful. All the other information are input successful as well except of The textarea thingy.

Using XAMPP.

The reason why i put form action as a link is because i want it to find my file.

Below are my codes

Code for HTML;

<!DOCTYPE html>
<html lang="en">

    <head>
        <meta charset="utf-8"/>
        <title> Competition Organizer </title>
        <link rel="stylesheet" href="main.css">
    </head>

    <body>
        <ul> 
            <li><a href="">Log Out</a></li>
            <li><a>Notification</a></li>
            <li><a href="Report.html">Generate Report</a></li>
            <li><a href="Admin.html">Home</a></li>
            <li style="float:left;color:white;">Competition Management</li>
        </ul>
        <form action="http://localhost/GCSweb/add.php" method="POST">
            <div>
                <br>
                <br>
                <br>

                <label><b>Competition Name</b></label>
                <input type="text" placeholder="Enter Competiton Name" name="compname" required>

                <label><b>Competition Mentor</b></label>
                <input type="text" placeholder="Enter Competiton Mentor Name" name="compmenname" required>

                <label><b>Competiton Description</b></label>
                <textarea rows="20" cols="50" name="compdescription" form="CompForm" placeholder="Enter Description Here..." required></textarea>

                <br>

                <input type="submit" value="Submit" name="submit">
            </div>
        </form>

    </body>

</html>

Code for PHP;

Connection to SQL;

<?php

$DB_host = "localhost";
$DB_user = "root";
$DB_password = "";
$DB_name = "competition_system";

try{
    $connection=new PDO("mysql:host=$DB_host;dbname=$DB_name",$DB_user.$DB_password);
    $connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    echo "Connected successfully"; 
    }
catch(PDOException $e)
    {
    echo "Connection failed: " . $e->getMessage();
    }
?>

Send data;

<?php

include "connection.php";

$compname = $_POST['compname'];
$compmenname = $_POST['compmenname'];
$compdescription = $_POST['compdescription']; //THis doesnt work


if(isset($_POST["submit"])){

    try{
    $sql = "INSERT INTO competition(Name,Host,Description) VALUES ('".$compname."','".$compmenname."','".$compdescription."')";

    if ($connection->query($sql)){
        echo"<script type= 'text/javascript'>alert('New Record Inserted Successfully');</script>";
    }else{
        echo "<script type= 'text/javascript'>alert('Data not successfully Inserted.');</script>";
    }

    $connection = null;
    }

    catch(PDOException $e){
        echo $sql . "<br>" . $e->getMessage();
    }
}
?>

Thank you

  • 写回答

1条回答 默认 最新

  • dqba94619 2017-09-14 03:13
    关注

    you're defining a non-existent form to include the textarea in - form="CompForm"

    remove that and your textarea will be included when you submit that form.

    to add, you only put in the form attribute for the textarea if the textarea is located outside the form tags

    example:

    <form id="my_form">
      <!-- other form elements here -->
    </form>
    
    <textarea name="my_txt" form="my_form"></textarea>
    
    评论

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)