php - 将表单中的数据插入数据库PHP MYSQL

标签 php mysql database forms

我正在尝试将表单中的数据发送到我的数据库中,但我似乎没有用。表字段是正确的。我是否有人能够看到出了什么问题?

表格:

<form class="myForm" role="form" action= "idea.php" method ="POST">
    <h1 style="margin-top:50px; margin-bottom:30px; text-align:center; color:#0f4155;">Idea Form</h1>

    <p1>Name:</p1>
    <input type="text" class="form-control" name="name" placeholder="Name">

    <p1>Originator:</p1>
    <input type="text" class="form-control" name="originator" placeholder="Originator">

    <p1>Alternative Contact</p1>
     <input type="text" class="form-control" name="altcontact" placeholder="Alternative Contact">

    <p1>Problem to Solve</p1>
     <input type="text" class="form-control" name="problem" placeholder="Problem to Solve">

    <p1>Description</p1>
    <textarea class="form-control" rows="3" name="description" placeholder="Description"></textarea>

    <p1>PO</p1>
    <input type="text" class="form-control" name="po" placeholder="PO">

    <p1>Archetypical Client</p1>
    <input type="text" class="form-control" name="archclient" placeholder="Arcetypical Client">

    <p1>Urgency</p1>
    <input type="text" class="form-control" name="urgency" placeholder="Urgency" style="margin-bottom: 20px">

    <p1>Technology/Platform</p1>
    <input type="text" class="form-control" name="technology" placeholder="Technology/Platform">

    <p1>Number of Sprints</p1>
    <input type="number" class="form-control" name="sprints" placeholder="Number of Sprints">

    <p1>Progress</p1>
    <input type="text" class="form-control" name="progress" placeholder="Progress">

    <input class="submit" name="submit" type="submit" value="Submit">

</form>  

PHP:

if ($_SERVER["REQUEST_METHOD"] == "POST") { //if new idea is being added

    $id = '';
    $name = $_POST['name'];
    $originator = $_POST['originator'];
    $altcontact = $_POST['altcontact'];
    $problem = $_POST['problem']; 
    $description = $_POST['description']; 
    $po = $_POST['po'];
    $archclient = $_POST['archclient']; 
    $urgency = $_POST['urgency']; 
    $technology = $_POST['technology']; 
    $sprints = $_POST['sprints']; 
    $progress = $_POST['progress']; 
    $status = "submitted"; 


    $strsq0 = "INSERT INTO idea (`id`,`name`, `originator`, `alternative_contact`, `problem`, `description`, `po`, `arch_client`, `urgency`, `technology`, `sprints`, `progress`, `status`) VALUES ('" . $name . "," . $name . "," . $originator . "," . $altcontact . "," . $problem . ", " . $description . ", " . $po . "," . $archclient . ", " . $urgency . ", " . $technology . ", " . $sprints . ", " . $progress . ", " . $status . "');"; //query to insert new idea
    if ($mysqli->query($strsq0)) {
        echo "Insert success!";
    } else {
        echo "Cannot insert into the data table; check whether the table is created, or the database is active. "  . mysqli_error();
    }
}

最佳答案

如果 idauto increment 则将其从 values() 中添加 NULL 的查询中移除,同样报价管理不当

$strsq0 = "INSERT INTO idea (`name`, `originator`, `alternative_contact`, `problem`, `description`, `po`, `arch_client`, `urgency`, `technology`, `sprints`, `progress`, `status`) VALUES ('$name','$originator','$altcontact ','$problem', '$description', '$po','$archclient', '$urgency', '$technology', '$sprints','$progress', '$status')"; //query to insert new idea

更多调试

echo "INSERT INTO idea (`name`, `originator`, `alternative_contact`, `problem`, `description`, `po`, `arch_client`, `urgency`, `technology`, `sprints`, `progress`, `status`) VALUES ('$name','$originator','$altcontact ','$problem', '$description', '$po','$archclient', '$urgency', '$technology', '$sprints','$progress', '$status')";
exit;
$strsq0 = "INSERT INTO idea (`name`, `originator`, `alternative_contact`, `problem`, `description`, `po`, `arch_client`, `urgency`, `technology`, `sprints`, `progress`, `status`) VALUES ('$name','$originator','$altcontact ','$problem', '$description', '$po','$archclient', '$urgency', '$technology', '$sprints','$progress', '$status')"; //query to insert new idea

然后复制这个打印查询并在phpMyadmin中运行,运行打印查询后检查是否有任何错误。

关于php - 将表单中的数据插入数据库PHP MYSQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34435605/

相关文章:

php - Mac 终端/MySQL 配置问题 |错误 2002 (HY000) : Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

mysql - MariaDB 显示列权限

php - 使 mysql 查询连接到下拉菜单中选定的表

sql - Visual Studio 2012 无法在 Asp.net 网站中保存我的 SQL 数据库

c# - 查询 - 基于行的表

php - 检查用户权限

php - Laravel 多对多自引用表只能以一种方式工作

php - Mysql - 在一个字段标题下显示多行

mysql - Grafana世界地图面板: latitude and longitude in mysql cannot display points on map

java - 如何将带有缩写记录的sqlite数据库添加到android项目中