0

I'm new to PHP, I have no clue what I'm doing. I'm trying to perform an insert into my MSSQL database. Not really sure why this is not working.

function Register_WBG_Tester($Email, $FullName, $ChatHandle, $Product, $PreferedGenre, $PreviousTester, $AgeGroup, $PlayTime, $Discord, $NDA)
{
    sqlsrv_configure('WarningsReturnAsErrors',0);
    $query;
    $result;

    $query = (string)"
    DECLARE @Response AS BIT = 0;
    IF NOT EXISTS(SELECT Email FROM [dbo].[WBG_Tester] WHERE [Email] = $Email) BEGIN
    INSERT INTO [dbo].[WBG_Tester]
               ([Email]
               ,[Full_Name]
               ,[Chat_Handle]
               ,[Product]
               ,[Prefered_Genre]
               ,[Previous_Tester]
               ,[Age_Group]
               ,[Play_Time]
               ,[Discord]
               ,[NDA_Agreement])
         VALUES
               ($Email
               ,$FullName
               ,$ChatHandle
               ,$Product
               ,$PreferedGenre
               ,$PreviousTester
               ,$AgeGroup
               ,$PlayTime
               ,$Discord
               ,$NDA
               )

        SET @Response = 1
    END ELSE BEGIN
        SET @Response = 0
    END

    SELECT @Response"

    $result =(bool)mssql_query($query);

    return $result;        
}

I've never worked with PHP before, mostly work with .Net I would prefer to exec calling a stored proc rather then string query. Any help would be great. Everything I've found was for MySQL. seems to be preferred for PHP.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
mholmes
  • 177
  • 2
  • 14

1 Answers1

0

This is how you can execute store procedures in php

sqlsrv_prepare ( resource $conn , string $sql [, array $params [, array $options ]] ) : mixed

Prepares a query for execution. This function is ideal for preparing a query that will be executed multiple times with different parameter values.

$sql = "EXEC stp_Create_Item @Item_ID = ?, @Item_Name = ?";
$stmt = sqlsrv_prepare($conn, $sql, $procedure_params);
if (!sqlsrv_execute($stmt)) {
    echo "Your code is fail!";
    die;
}
while($row = sqlsrv_fetch_array($stmt)){
    //Stuff
}

For more details please visit, php official documentation.

iamwebkalakaar
  • 358
  • 1
  • 9