mysql - 为什么我无法将数据插入数据库

标签 mysql sql database insert

这些是页面的代码:

<?php 
session_start();

if(isset($_SESSION['level'])){
if($_SESSION['level'] == 2  ){
require("../db/dbConn.php");


$submitted = isset($_POST['submit']);
if($submitted){
    //check user's input
    if(isset($_POST['issue_type'])){
        $issue_type =$_POST['issue_type'];
    }
    else {
       $issue_type = null;
        echo '<p><font color="red">Please Select a Issue Type</font></p>';
    }

    if(isset($_POST['description'])){
        $description=$_POST['description'];
    }
    else{
        $description = null;
         echo '<p><font color="red">You forgot to enter a description</font>          </p>';
    }

    if(isset($_POST['reported_account_id'])){
    $reported_account_id = $_POST['reported_account_id'];
    }
    else{
        $reported_account_id = null;
        echo '<p><font color="red">You forgot to enter your ID</font></p>';
    }
    if(isset($_POST['DateTimeCreated'])){
        $DateTimeCreated=$_POST['DateTimeCreated'];
    }
     else{
        $DateTimeCreated= null;
        echo '<p><font color="red">You forgot to enter the date and time of            the Issue </font></p>';
     }


    //Prepare the Insert Statement
    $stmt = "INSERT INTO problem (issue_id, description,   reported_account_id, DateTimeCreated) VALUES ('$issue_type', '$description','$reported_account_id','$DateTimeCreated')";
    $result = mysqli_query($conn, $stmt);
    $conn->close();
    //TODO 5: Check result of executing insert statement and rows inserted.     Print user's input if 1 row is inserted successfully,
    // else print error message
    if($result==true){
        echo '<p><font color="green">The problem has been created. Thank     you</font></p>';
        echo '<p>Registration Successful Please <a href="../problemTableCompany.php">Click Here</a>';
}     else {
            echo "<p><font color=red><b>Data not saved. Please try again</b></font></p>";
            echo '<p>Inserting Failed Please <a   href="../problemcreateCompany.php">Click Here to Try Again</a>';

    }
    }}
}     else {
    header("Location: ../index.php");
}
?>

我无法将表单页面中的详细信息插入到数据库中。这是我面临的唯一问题。请帮我指出我犯的错误。

最佳答案

要解决这个问题,请更换

$stmt = "INSERT INTO problem (issue_id, description,   reported_account_id, DateTimeCreated) VALUES ('$issue_type', '$description','$reported_account_id','$DateTimeCreated')";

$stmt = "INSERT INTO problem (issue_id, description,   reported_account_id, DateTimeCreated) VALUES ('"+$issue_type+"', '"+$description+"','"+$reported_account_id+"','"+$DateTimeCreated+"')";

关于mysql - 为什么我无法将数据插入数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34836846/

相关文章:

mysql - 数据库关系循环,如何打破呢?

javascript - 如何访问 php/mysql 查询值以在 jQuery 中使用?

mysql - 将数据从 PostgreSQL 传输到 MySQL

sql - 将空字符串插入 SQL Server 的 INT 列

sql - 如何对包含星号的 PostgreSQL 中的 VARCHAR 列进行排序

c++ - 从 sqlite3 数据库(.db 文件)检索数据并将其存储在 C++ 中的简单字符串中

mysql - 在 django 模型中存储时区的假设?

mysql - 我有一个充满 SQL 命令的文件。如何将其插入MySQL数据库?

SQL Azure - 创建外部数据源 : Location as a Parameter?

mysql - 如何在RackSpace专用服务器上发布数据库?