我正在尝试使用 SQl
和 PHP
以及 ODBC 连接
将新记录添加到我的数据库
中>。当我填写表格并单击“添加”时,什么也没有发生!这是我的代码:
if(isset($_POST['add'])){
$conn=odbc_connect($data_source,$user,$password);
$Address1 = $_POST['Address1'];
$Address2 = $_POST['Address2'];
$Address3 = $_POST['Address3'];
$Address5 = $_POST['Address5'];
$contactName = $_POST['contactName'];
$pic = $_POST['pic'];
$emailAddress = $_POST['emailAddress'];
$number = $_POST['number'];
$pname = $_POST['pname'];
$type = $_POST['type'];
$emailAddress = $_POST['storage'];
$number = $_POST['allergen'];
$phama = $_POST['phama'];
$health = $_POST['health'];
$qp = $_POST['qp'];
$transport = $_POST['transport'];
$qac = $_POST['qac'];
$qad = $_POST['qad'];
$stmt = "INSERT INTO dbo.tblVersions2 (QuoteNumber, Address1, Address2, Address3, Address4, ContactName, PositionInCompany, EmailAddress, TelephoneNumber, ProductName, TypeOfService, StorageConditions, AllergenInfo) VALUES(NULL, '$Address1',
'$Address2', '$Address3', '$Address4', '$Address5', '$contactName', '$pic', '$emailAddress', '$number', '$pname', '$type', '$storage',
'$allergen')";
$result = odbc_execute($conn, $stmt);
if($result){
echo "New Product Added";
}
else {
echo "Product not Added";
}
}
?>
请帮我看看哪里出了问题,谢谢!
最佳答案
如果什么都没发生,我会这么说
if(isset($_POST['add']))
是假的。
您获得的值多于查询中的列数。 另外,使用参数:https://blog.codinghorror.com/give-me-parameterized-sql-or-give-me-death/
关于php - SQL 添加不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38475241/