Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7893021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:00:59+00:00 2026-06-03T07:00:59+00:00

Why are my SQLSRV queries not executing? It doesn’t echo anything like its supposed

  • 0

Why are my SQLSRV queries not executing?

It doesn’t echo anything like its supposed to on the IF ELSE failure does anyone see what my issue is? I can’t figure out whats wrong, it looks like it should be working to me.

PHP Code:

/* IF NULL EXISTS of DATEIN or DATEOUT then UPDATE else INSERT*/
$datein_s="SELECT TOP 1 datein FROM clocked WHERE datein IS NULL AND userid=? ORDER BY datein DESC";
$datein_sr=sqlsrv_query($dbconnect,$datein_s,$params);
$datein=sqlsrv_fetch($datein_sr);
$datein_q1="UPDATE clocked SET datein=GETDATE() WHERE EXISTS(SELECT TOP 1 datein FROM clocked WHERE datein IS NULL AND userid=? ORDER BY datein DESC);";
$datein_qr1=sqlsrv_query($dbconnect,$datein_q1,$params);
$datein_q2="INSERT INTO clocked(datein) VALUES(GETDATE(),?);";
$datein_qr2=sqlsrv_query($dbconnect,$datein_q2,$params);

$dateout_s="SELECT TOP 1 dateout FROM clocked WHERE dateout IS NULL AND userid=? ORDER BY dateout DESC";
$dateout_sr=sqlsrv_query($dbconnect,$dateout_s,$params);
$dateout=sqlsrv_fetch($dateout_sr);
$dateout_q1="UPDATE clocked SET dateout=GETDATE() WHERE EXISTS(SELECT TOP 1 dateout FROM clocked WHERE dateout IS NULL AND userid=? ORDER BY dateout DESC);";
$dateout_qr1=sqlsrv_query($dbconnect,$dateout_q1,$params);

if($datein===null)
{
$datein_qr1;
}
else if ($dateout===null)
{
$dateout_qr1;
}
else if ($datein===null&&$dateout===null)
{
$datein_qr1;
}
else if ($datein!==null&&$dateout!==null)
{
$datein_qr2;
}
else
{
echo "ERROR your query may be broken!";
}

/* END IF */
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:01:00+00:00Added an answer on June 3, 2026 at 7:01 am

    I can’t quite follow the logic here, but I think the problem is that the lines at the top:

    $datein_qr2=sqlsrv_query($dbconnect,$datein_q2,$params);
    

    are running the queries – I think what you’re wanting to do is just initialise the queries at the top, and then run the appropriate one in the if statements, with:

    $datein_qr1;
    

    You’ll need to move the sqlsrv_query line to inside the if statements.

    Also, the third if statement won’t ever be reached:

    else if ($datein===null&&$dateout===null)
    

    You’re already checking to see if datein and dateout are null on the two previous if statements.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am debating between using MsSQL and SQLSrv to connect to SQL Server. Our
I have a web application using PHP and PDO with SQLSRV prepared statements to
I'm getting intermittent Error 101 connection reset and Error 15 Socket Not Connected from
I'm am looking for a function similar to mysql_real_escape_string for the SQLSRV library. Specifically
I'm trying to switch some hard-coded queries to use parameterized inputs, but I've run
I am trying to connect Azure database with PHP. I installed sqlsrv driver. It
I have a command like.. $Res = $db->ExecSQL($sQry, $param); while ($row = sqlsrv_fetch_array($Res)){ ..
I want to echo the result from a date column after a database query,
I am using the sqlsrv ms drivers for php, which work fine (tested with
I'm using the sqlsrv extension to connect to a MSSQL (I think 2005) database

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.