选择查询工作但不插入查询

时间:2018-01-11 05:17:53

标签: javascript php jquery html

  <?php
    $sql = "SELECT MAX(REQUEST_ID) AS REQUEST_ID FROM TBL_REQUEST;";
    $stmt = sqlsrv_query( $conn, $sql );
    if( $stmt === false) {
        echo "alert('DataBase Error');";
    }
    else{
        $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC);
        $newReqId=$row['REQUEST_ID']+1;
    }
    $sql = "INSERT INTO TBL_REQUEST VALUES(".$newReqId.",\'ISSUE\',\'Test\',\'Test\',\'NSNS05\',1);";
    $newsql = $sql;
    $stmt = sqlsrv_query( $conn, $newsql );
    if( $stmt === false) {
        echo "alert('Not Inserted '+assoc_id+' ".$stmt." '+' ".$newsql." ');";
    }
    else{
        echo "alert('Inserted '+assoc_id+' ".$stmt."');";
    }

?>

在上面的代码中,我使用了2个SQL语句,第一个是一个select语句,可以正常工作并从表中获取数据,但是当我在同一个表上执行Insert时,它不起作用...

INSERT INTO TBL_REQUEST VALUES(4016,'ISSUE','Test','Test','NSNS05',1); 

那是

的字符串

1 个答案:

答案 0 :(得分:0)

为什么在""之间使用"" ' ' $newReqId

$sql = "INSERT INTO TBL_REQUEST VALUES(".$newReqId.",\'ISSUE\',\'Test\',\'Test\',\'NSNS05\',1);";