无法通过php文件将数据插入MySQL

时间:2017-11-20 05:15:54

标签: php mysql

我知道这些问题已被低估或关闭,但我已经完成了所有之前提出的问题,但找不到任何解决方案。代码应该接受来自HTML表单的输入并将其插入MySQL数据库并显示在另一个页面上,但不知何故,我最终得到查询失败的语句并重定向到Login页面。

<?php
        if (isset($_POST['eTransport_ID'])){
            $id = ($_POST['eTransport_ID']);
        }

        if (isset($_POST['Phone_No'])){
            $phone = ($_POST['Phone_No']);
        }

        if (isset($_POST['Amount'])){
            $amount = ($_POST['Amount']);
        }
        $DATEE = date("Y-m-d");
        $TIMEE = date("h:i:sa");

        $query = "INSERT INTO recharge_history(Date, Time, Amount, Agent_No, eTransport_ID) VALUES ('$DATEE', '$TIMEE', '$amount', 'WEB', '$id')";
        $added = mysqli_query($conn, $query);

        if(!$added){
            die("Database query failed.");
        }
        else{
            echo "Data Entered Successfully";
        }

        mysqli_close($conn);
    ?>

MySQL Table

2 个答案:

答案 0 :(得分:0)

  1. 这是BAD代码,它有严重的SQL注入漏洞,所以请单独查看(您的问题不是关于安全性)
  2. 我假设'日期'是日期栏
  3. 我假设'时间'是时间列
  4. 看起来Agent_No可能是INT列,但您正在插入一个字符串。我已经取代了“1”,所以你必须单独看一下。
  5. 如果我的假设是正确的,只需将查询行更改为此(即:复制并粘贴):

    yourImageView.isHighlighted = !yourImageView.isHighlighted
    
    if yourImageView.isHighlighted
    {
      //so now the UIImageView shows stop image that means we are in recording mode
      // do the actions that are to be done in recording mode like start recording updating other UI etc 
    }
    else
    {
     //so now the UIImageView shows Record/Trigger image that means are in normal mode or not recording
      // do the actions that are to be done in normal mode like stop recording (if required )updating other UI etc 
    }
    

答案 1 :(得分:0)

$ query =“INSERT INTO recharge_history(日期,时间,金额,Agent_No,eTransport_ID)价值('$ DATEE','$ TIMEE','$ amount','WEB','$ id')”; < / p>

你能写这样的查询吗?

$ query =“INSERT INTO recharge_history(日期,时间,金额,Agent_No,eTransport_ID)价值($ DATEE,$ TIMEE,$ amount,$ phone,$ id)”;