【问题标题】:SQL ADDNOT WORKINGSQL 插件不起作用
【发布时间】:2025-12-31 03:50:10
【问题描述】:

我正在尝试使用带有ODBC connectionSQlPHP 将新记录添加到我的database。当我填写表格并单击“添加”时,什么也没有发生!这是我的代码:

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"; 

}
    }
?>

请帮我找出问题所在,谢谢!

【问题讨论】:

    标签: php mysql sql odbc add


    【解决方案1】:

    如果什么都没发生,我会说

    if(isset($_POST['add']))
    

    是假的。

    您获得的值比查询中的列多。 另外,使用参数:https://blog.codinghorror.com/give-me-parameterized-sql-or-give-me-death/

    【讨论】:

    • 在清除变量名称等一些错误后,我现在返回了 else 位“已添加产品”,但仍然没有添加到数据库中!有什么想法吗?
    • '未添加产品" *
    • 好吧,如果 odbc_execute 明显失败,您可以尝试使用 php.net/manual/de/function.odbc-error.php 获取错误信息