从动态文本框sqlserver多次插入

时间:2018-07-02 18:41:21

标签: php sql-server

请帮助我的代码有什么问题!需要从动态文本框中插入多个数据。在此先感谢您的帮助!

<?php       
if (isset($_POST['stnp1ecimSubmit'])) {

$test = $_POST['test'];
$test2 = $_POST['test2'];
$test3 = $_POST['test3'];
$test4 = $_POST["test4"];
$test5 = $_POST["test5"];


foreach($_POST['test'] as $a => $b){
$stmt = sqlsrv_query( $conn, "SELECT * FROM [dbo].[tbltest] WHERE 
tbltest='$test[$a]' ") ;
if($stmt){
$row = sqlsrv_has_rows( $stmt );
if ($row === true){

$user_error =" user is already exist!";
}else{


$query = "INSERT INTO [dbo].[tbltest] (tbltest, tbltest2, tbltest3, 
tbltest4,tbltest5)
VALUES ('" . $test[$a] . "', '" . $test2[$a] . "', '" . $test3[$a] . "', '" . 
$test4[$a] . "', '" . $test5[$a] . "')";


$results = sqlsrv_query($conn , $query);
echo"  <script>alert('Successfully Added!')</script>";
exit();
}
}
}
}
?>  

这是我的示例文本框

<input type="number" name="test1[]"   title="Enter Badge Number" style="width:150px;" placeholder="Enter Badge ID.." class="form-control" required autofocus>

0 个答案:

没有答案