Как вычислить строку SQL server с помощью функции PHP?
I have the following PHP function that should evaluate a string, to check "if it exists in the database or not" the string comes to the $row variable as an email format. How can I evaluate the string? Please help and thank you!
<?php if (isset($_POST['submit'])) { $firstName = $_POST['firstName']; $lastName = $_POST['lastName']; $username = $_POST['username']; checkUsername($firstName, $lastName, $username); } function checkUsername($firstName, $lastName, $username){ include 'connect_sql.php'; $sql = "SELECT UserName FROM [Membership].[dbo].[Center] WHERE UserName='$username'"; $stmt = sqlsrv_query( $conn, $sql ); $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC); if(sqlsrv_num_rows($row) > 0 ) { echo "<div id='loginmsg'>Member already exist</div>"; } else { echo "<div id='loginmsg'>Member is new</div>"; } } ?>
Что я уже пробовал:
I tried the following (sqlsrv_num_rows($row) > 0 ) having fetch a row but it jumps to else condition. I tried running the sql query directly at the database and it works fine. I'm not sure what's wrong with the code or how to handle when it finds a row to echo that the record exist or not. Please help!