SQL PHP |相同的代码不起作用

时间:2016-07-08 09:31:10

标签: php sql-server command

编辑!

当我在SQL Server Management上执行它时,此代码有效,但当我尝试在我的php代码上使用它时,它失败了。我找不到问题的根源。我该如何解决这个问题?

我没有从PHP收到任何错误消息!

SQL代码:

INSERT INTO [gyakornok].[dbo].[t_corps] (value, status_id)
VALUES ('blablabla', (SELECT id FROM [gyakornok].[dbo].[t_status] WHERE value='Active'))

PHP代码:

$corp = $_POST['corp'];
$userquery = "INSERT INTO [gyakornok].[dbo].[t_corps] (value, status_id)";
$userquery .= " VALUES ('$corp', (SELECT id FROM [gyakornok].[dbo].[t_status] WHERE value='Active'))";
$userquery = sqlsrv_query($conn, $userquery);

1 个答案:

答案 0 :(得分:1)

php中的sql代码不一样......

以下是相同的:

$userquery = "INSERT INTO [gyakornok].[dbo].[t_corps] (value, status_id)";
$userquery .= " VALUES ('$corp', (SELECT id FROM [gyakornok].[dbo].[t_status] WHERE value='Active'))";
$userquery = sqlsrv_query($conn, $userquery);

没有'围绕SELECT