0

我似乎在将记录插入数据库时​​遇到问题。我收到了成功消息,但是当我查看数据库中的信息时,所有字段都是木板。我的语法有错误吗?

if(isset($_POST['client'])) {
    $id = (int)$id;
    $client_to_insert = mysql_real_escape_string($_POST['client']);
    $contact_to_insert = mysql_real_escape_string($_POST['contact']);
    $title_to_insert =  mysql_real_escape_string($_POST['title']);
    $assigned_to_insert = mysql_real_escape_string($_POST['assigned']);
    $start_date_to_insert = stripslashes($_POST['start_date']);
    $end_date_to_insert = stripslashes($_POST['end_date']);
    $status_to_insert = mysql_real_escape_string($_POST['status']);
    $amount_to_insert = mysql_real_escape_string($_POST['amount']);
    $costs_to_insert = mysql_real_escape_string($_POST['costs']);
    $costs2_to_insert = mysql_real_escape_string($_POST['costs2']);
    $costs_item_to_insert = mysql_real_escape_string($_POST['costs_item']);
    $costs_item2_to_insert = mysql_real_escape_string($_POST['costs_item2']);
    $notes_to_insert = mysql_real_escape_string($_POST['area']);
    $feeA_to_insert = mysql_real_escape_string($_POST['feeA']);
    $feeB_to_insert = mysql_real_escape_string($_POST['feeB']);
    $feeC_to_insert = mysql_real_escape_string($_POST['feeC']);
    $feeD_to_insert = mysql_real_escape_string($_POST['feeD']);
    $feeE_to_insert = mysql_real_escape_string($_POST['feeE']);
    $feeF_to_insert = mysql_real_escape_string($_POST['feeF']);
    $feeG_to_insert = mysql_real_escape_string($_POST['feeG']);
    $feeH_to_insert = mysql_real_escape_string($_POST['feeH']);
    $feeI_to_insert = mysql_real_escape_string($_POST['feeI']);
    $feeK_to_insert = mysql_real_escape_string($_POST['feeK']);
    $feeL_to_insert = mysql_real_escape_string($_POST['feeL']);
    $feeM_to_insert = mysql_real_escape_string($_POST['feeM']);
    $feeN_to_insert = mysql_real_escape_string($_POST['feeN']);
    $contract_to_insert = mysql_real_escape_string($_POST['contract']);
    $outofhouse_to_insert = mysql_real_escape_string($_POST['outofhouse']);
    $vendor_to_insert = mysql_real_escape_string($_POST['vendor']);
    $vendor1_to_insert = mysql_real_escape_string($_POST['vendor1']);
    $billed_to_insert = mysql_real_escape_string($_POST['billed']);
    $billing_need_to_insert = mysql_real_escape_string($_POST['billing_need']);
    $extended_billing_to_insert = mysql_real_escape_string($_POST['extended_billing']);
    $contract_value_to_insert = mysql_real_escape_string($_POST['contract_value']);
    $retainer_value_to_insert = mysql_real_escape_string($_POST['retainer_value']);


    $query = mysql_query("INSERT INTO projects (
    id,
    client,
    contact,
    title,
    assigned,
    start_date,
    end_date,
    status,
    amount,
    costs,
    costs2,
    costs_item,
    costs_item2,
    notes,
    feeA, 
    feeB,
    feeC,
    feeD,
    feeE,
    feeF,
    feeG,
    feeH, 
    feeI, 
    feeK, 
    feeL, 
    feeM, 
    feeN, 
    contract, 
    billed, 
    billing_need, 
    extended_billing, 
    vendor, 
    vendor1, 
    outofhouse, 
    retainer_value, 
    contract_value
    )

    VALUES (
    '$id' ,
    '$client' ,
    '$contact' ,
    '$title' ,
    '$assigned' ,
    '$start_date' , 
    '$end_date' , 
    '$status' , 
    '$amount' , 
    '$costs' , 
    '$costs2' ,
    '$costs_item' ,
    '$costs_item2' , 
    '$notes' , 
    '$feeA' , 
    '$feeB' ,
    '$feeC' ,
    '$feeD' , 
    '$feeE' , 
    '$feeF' , 
    '$feeG' , 
    '$feeH' , 
    '$feeI' , 
    '$feeK' , 
    '$feeL' , 
    '$feeM' , 
    '$feeN' , 
    '$contract' , 
    '$billed' , 
    '$billing_need' , 
    '$extended_billing' , 
    '$vendor' ,
    '$vendor1' ,
    '$outofhouse' , 
    '$retainer_value' , 
    '$contract_value' );");


    if($query) {
        $message = "Success your Project has been added!";

    }else{
        $message = "An error occurred while adding this Project";
    }

}
?>
4

3 回答 3

1

您的 SQL 看起来不错 [就上下文允许的情况而言](这就是为什么每次运行时都会看到一个新行的原因)但是,我建议您在运行查询之前死掉并首先输出它。所以你可以看看你可能做错了什么。

$sql   = "INSERT INTO projects (...";
var_dump($sql);
die();

$query = mysql_query($sql);
于 2012-12-29T16:22:43.713 回答
1

正如@hakre 提到的,sql 看起来不错,但你可以使用

mysql_query("INSERT...") or die(mysql_error());

检查数据库中是否存在任何问题,例如缺少或错误命名的字段

于 2012-12-29T16:27:36.483 回答
0

在类似情况下对我来说总是有效的是回显 sql 查询并将其直接复制并粘贴到数据库中,然后查看是否有任何问题。此外,可能值得检查mysql_affected_rows($sql).

于 2012-12-29T16:59:33.857 回答