如何使用PHP函数评估SQL服务器字符串? [英] How to evaluate a SQL server string with a PHP function?
本文介绍了如何使用PHP函数评估SQL服务器字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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>";
}
}
?>
我尝试了什么:
What I have tried:
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!
推荐答案
行变量作为电子邮件格式。我该如何评估字符串?请帮忙谢谢!
row variable as an email format. How can I evaluate the string? Please help and thank you!
<?php
if (isset(
_POST [' submit'])){
_POST['submit'])) {
>
firstName =
firstName =
这篇关于如何使用PHP函数评估SQL服务器字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文