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!
Quote:It is because sqlsrv_query() uses SQLSRV_CURSOR_FORWARD cursor type by default. However, in order to get a result from sqlsrv_num_rows(), you should choose one of these cursor types below: SQLSRV_CURSOR_STATIC SQLSRV_CURSOR_KEYSET SQLSRV_CURSOR_CLIENT_BUFFERED
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)