我无法将数据插入我的数据库,但我没有任何错误

时间:2017-06-11 10:29:48

标签: php

这是我的PHP代码。你能帮我么。我的数据库中没有数据。

    <?php

    require_once("dbconnect.php");

    session_start();


    for ($x = 0; x < $_POST['reimcounter']; $x++) {

    $date = $_POST['date'];
    $tin = $_POST['tin'];
    $address = $_POST['address'];
    $particulars = $_POST['particulars'];
    $referencenumber = $_POST['refno'];
    $total = floatval(preg_replace('/[^\d\.]/', '', $_POST['total' . $x]));
    $nonvat = floatval(preg_replace('/[^\d\.]/', '', $_POST['nonvat' . 
    $x]));

我的插入代码有什么问题吗?

    $sql = "INSERT INTO rtco_cms.dbo.Reimbursement VALUES (?, ?, ?, ?, ?, ?, 
    ?, ?, ?)";

    $params = array($date, $tin, $SESSION['empid'], $address, 
    $SESSION['clientid'], $particulars, $referencenumber, $nonvat, $total);

    $stmt = sqlsrv_query($conn, $sql, $params);
    }

    header("location: ../reimbursement.php");


    ?>

1 个答案:

答案 0 :(得分:0)

更改此

$params = array($date, $tin, $SESSION['empid'], $address, 
$SESSION['clientid'], $particulars, $referencenumber, $nonvat, $total);

$params = array($date, $tin, $_SESSION['empid'], $address, 
$_SESSION['clientid'], $particulars, $referencenumber, $nonvat, $total);

会话变量调用错误。希望它有所帮助

更新您的插入查询,例如,请参阅此查询:

tsql= "INSERT INTO dbo.vF_events (
        username,
        Rft,
        Ging,
        description,
        date,
        trdate) 
        VALUES
        (?, ?, ?, ?, ?, ?)";
        $var = array($username, $sort, $ag,     $description, $date, $trdate);
        if (!sqlsrv_query($conn, $tsql, $var))
             {
        die('Error: ' . sqlsrv_errors());
             }
        echo "record added";