$sql = "insert into dbo.".$st_tab." (bike_id,st_id";
if($st_tab === "st1_rec_id"||$st_tab === "st2_rec_id"||$st_tab ==="st3_rec_id")
{
$sql .= ",ln_id";
}
$sql .= ",times,date) values (?,?";
if($st_tab === "st1_rec_id"||$st_tab === "st2_rec_id"||$st_tab ==="st3_rec_id")
{
$sql .= ",?";
}
$sql .= ",?,?)";
echo $sql;
if($st_tab === "st1_rec_id"||$st_tab === "st2_rec_id"||$st_tab ==="st3_rec_id")
{
$var = array($bike_id,$station,$line,$time,$date);
}
else
{
$var = array($bike_id,$station,$station,$time,$date);
}
$insert = sqlsrv_query($conn,$sql,$var);
if($insert === false)
{
die(print_r(sqlsrv_errors(),true));
}
else
{
foreach($var as $x => $a)
{
echo $x." : ".$a." ";
}
echo "<br> 1 Record Added";
}
due that code I got an query error
Array ( [0] => Array ( [0] => 42000 [SQLSTATE] => 42000 [1] => 102 [code] => 102 [2] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Incorrect syntax near 'chs_st2_rec'. [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Incorrect syntax near 'chs_st2_rec'. ) )
I can't identify what's error and where it's.
chs_st2_recto be seen; yet that's what the error message is about). If this isn't actually the relevant code, you won't get it answered. Please invest a bit more time in adding details (See How to ask, and Writing the perfect question, or MCVE…)