内容未发布到数据库但获得成功消息

时间:2012-12-29 16:08:02

标签: php mysql sql

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

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

}
?>

3 个答案:

答案 0 :(得分:1)

你的SQL看起来很好[就上下文允许这样说](这就是你每次运行时都会看到一个新行的原因)但是,我建议你先运行查询并先输出它。所以你可以看看你可能做错了什么。

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

$query = mysql_query($sql);

答案 1 :(得分:1)

正如@hakre所提到的,sql看起来很好,但你可以使用

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

检查数据库中是否存在遗漏或错误名称等问题

答案 2 :(得分:0)

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