PHP Script INSERT INTO SELECT does not insert, with no errors [closed]

60
January 27, 2021, at 04:20 AM
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.

Want to improve this question? Update the question so it's on-topic for Stack Overflow.

Closed 15 hours ago.

Improve this question

I have a php script with the following code, this script runs fine. It returns an integer of 0 or 1.

    $sql = 'select isnull((SELECT Access.Granted
            FROM users
            INNER JOIN Access ON users."ID"=Access."ID"
            where users."ID" in (SELECT "ID" from users where CardUid = ? and Access.Granted =\'1\') 
            and Access.DoorMac = ?
            and cast(current_timestamp as time(7)) > StartTime
            and cast(current_timestamp as time(7)) < EndTime),0)';
    
    $params = array($carduid, $mac);
    
    
    $stmt = sqlsrv_query( $conn, $sql, $params);
        if( $stmt === false ) 
          {
           die( print_r( sqlsrv_errors(), true));
          }
    while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_NUMERIC) ) 
          {
          $result=$row[0];
          }

But when I try to do an INSERT INTO it does not insert, does not throw error, if i misname a column it throws an error, if run the same code in SSMS with static values it works correctly.

    $sql = 'INSERT INTO Door1 (Mac, CardUid, FirstName, LastName, GivenName, "ID", Granted) 
            SELECT ?,?, users.FirstName, users.LastName, users.GivenName, users."ID", ?
            FROM users
            INNER JOIN Access on users."ID" = Access."ID"
            where users."ID" in (SELECT "ID" from users where CardUid = ?)';
    $params = array($mac, $carduid, $result, $mac);
    
    $stmt = sqlsrv_query( $conn, $sql, $params);
    
    if( $stmt === false ) {
         die( print_r( sqlsrv_errors(), true));
    }
Answer 1

Found my problem, in

$params = array($mac, $carduid, $result, $mac);

should be

$params = array($mac, $carduid, $result, $carduid);

READ ALSO
SQL query to select students who have taken all subjects from subjects table

SQL query to select students who have taken all subjects from subjects table

I have two tables, student_records and subjectsI have to find out those students who have taken all the subjects (1,2,3) from the subjects table

53
Sticky view with scrollview and expandable background

Sticky view with scrollview and expandable background

How can we make a view in red border sticky which does not depend on the height of black background and always stick with a border of black and white background

93
div element hides when load() function is called

div element hides when load() function is called

I'm working on making ordering by some criterias(eg

63
Displaying Dynamic placeholder content on Textbox in ReactJS

Displaying Dynamic placeholder content on Textbox in ReactJS

I wanted to place a dynamic content in placeholder inside my textbox component in ReactI have declared a function which returns the placeholder, passing the value as argument

83