I have a form that I use on MySQL/PHP and need to convert it to MSSQL/PHP. This is the area that I’m struggling with, what am I doing wrong?
No error, when I submit the form it just reloads, not submitting any data to the DB.
<?php
if (isset($_POST['Vendor_ID'])) { //Check for a field that is mandatory to do the inserted
$Vendor_ID = sqlsrv_escape_string($_POST['Vendor_ID']);
$ProductName_ID = sqlsrv_escape_string($_POST['ProductName_ID']);
$version = sqlsrv_escape_string($_POST['version']);
$serial = sqlsrv_escape_string($_POST['serial']);
$ProductKey = sqlsrv_escape_string($_POST['ProductKey']);
$Department_ID = sqlsrv_escape_string($_POST['Department_ID']);
$ownername = sqlsrv_escape_string($_POST['ownername']);
$Computer = sqlsrv_escape_string($_POST['Computer']);
$Comments = sqlsrv_escape_string($_POST['Comments']);
$Acquired = sqlsrv_escape_string($_POST['Acquired']);
$Retired = sqlsrv_escape_string($_POST['Retired']);
$sql = "INSERT INTO dbo.KeyList_detail (
Vendor_ID,
ProductName_ID,
version,
serial,
ProductKey,
Department_ID,
Owner,
Computer,
Comments,
Acquired,
Retired)
VALUES(
$Vendor_ID,
$ProductName_ID,
$version,
$serial,
$ProductKey,
$Department_ID,
$Owner,
$Computer,
$Comments,
$Acquired,
$Retired)";
sqlsrv_query($con,$sql);
if (sqlsrv_query($con, $sql)) {
echo '<strong><em>Your data has been submitted</em></strong><br /><br />';
} else {
echo '<p>Error adding submitted info: ' . sqlsrv_error(). '</p>';
}
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">