我目前正在尝试解决如果条目不存在而将条目添加到数据库中的问题。但是,如果确实如此,并且用户名与数据库中的一个匹配,则会更新为其他输入。但是我目前收到错误:
sqlsrv_num_rows() expects parameter 1 to be resource
我的代码如下所示:
$describeQuery = ("INSERT INTO User
(userID, first_name, last_name)
VALUES ('".$Username."', '".$FirstName."', '".$LastName."');");
$results = sqlsrv_query($conn, $describeQuery);
if(sqlsrv_num_rows($describeQuery) == 0)
{
echo 'New entry added';
}
else
{
$describeQuery2= ("UPDATE User
SET first_name = '".$FirstName."',
last_name = '".$LastName."'
WHERE userID = '".$Username."'");
$results = sqlsrv_query($conn, $describeQuery2);
$describeQuery3= ("UPDATE Current_Location
SET first_name = '".$FirstName."',
last_name = '".$LastName."'
WHERE userID = '".$Username."'");
$results = sqlsrv_query($conn, $describeQuery3);
echo '<br>';
echo '<br>';
echo 'Entry updated';
任何帮助将不胜感激。