我有一个问题,我有一个存储过程插入查询和一个 PHP 表单...我需要通过在我的 PHP 中调用存储过程来将 fname 和 lname 保存到我的表中。单击按钮时我没有收到任何错误,但是当我查看表格时...没有插入数据...
PHP代码:
<?php
$serverName = " BONGBONG-PC ";
$connection = array( "Database"=>"benefit_insurance");
$conn = sqlsrv_connect( $serverName, $connection);
$btn=$_POST['button'];
$s_fname=$_POST['fname'];
$s_lname=$_POST['lname'];
$stmt = sqlsrv_prepare ($conn,'CALL insert_record(@fname, @lname)', array(&$s_fname,&$s_lname));
sqlsrv_execute ($stmt);
if( !$stmt ) {
die( print_r( sqlsrv_errors(), true));
}
echo "<script language=javascript>alert('ACCOUNT SAVED')</script>";
?>
HTML 代码:
<div id="login_body">
<form method="post" name="MyForm">
<p class="p3"> First Name: <input type="text" name="fname" placeholder="fname" class="aaa"/> </p>
<p class="p4"> Last Name: <input type="text" name="lname" placeholder="lname" class="aaa"/> </p>
<input type="submit" name="button" class="login" value="LOGIN"/>
</form>
</div>
SQL SERVER 中的存储过程
USE [benefit_insurance]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[insert_record]
@fname varchar(50) output,
@lname varchar(50) output
AS
BEGIN
insert into trylang (fname,lname) values (@fname,@lname)
END