2016-08-29 165 views
1

當我執行下面的代碼時,附加圖像中以黃色突出顯示的查詢將打印在頁面中。我不想打印該SQL。我的代碼段有什麼問題? INSERT期間正在執行sql查詢

enter image description here

if(isset($_REQUEST["stu_performance_activity_submit"])) 
    { 
    $stu_performance_main_category = $_REQUEST["stu_performance_main_category"]; 
    $stu_performance_sub_category = $_REQUEST["stu_performance_sub_category"]; 
    $stu_performance_activity_name = $_REQUEST["stu_performance_activity_name"]; 
    $stu_performance_activity_date = $_REQUEST["stu_performance_activity_date"]; 
    $stu_performance_activity_description = $_REQUEST["stu_performance_activity_description"]; 

    $newc = "INSERT INTO stu_performance_activity 
        (stu_performance_activity_id, 
        stu_performance_main_category, 
        stu_performance_sub_category, 
        stu_performance_activity_name, 
        stu_performance_activity_date, 
        stu_performance_activity_description) 
      VALUES ('', 
        '$stu_performance_main_category', 
        '$stu_performance_sub_category', 
        '$stu_performance_activity_name', 
        '$stu_performance_activity_date', 
        '$stu_performance_activity_description')"; 

    if($connection->query($newc) === TRUE) 
     { 

     } 
    else 
     { 
     echo "Error: " . $newc . "<br>" . $connection->error; 
     } 
    } 
+0

打印就像一個有用的wrror消息'$連接 - > error' – RiggsFolly

+0

你開始的PHP代碼以'<?php'標籤 – RiggsFolly

+0

這解決了這個問題。我錯過了添加<?php相反,有

回答

-1

主鍵應該是NULL。重寫查詢的方式一樣

$newc = "INSERT INTO stu_performance_activity 
        (stu_performance_activity_id, 
        stu_performance_main_category, 
        stu_performance_sub_category, 
        stu_performance_activity_name, 
        stu_performance_activity_date, 
        stu_performance_activity_description) 
      VALUES (NULL, 
        '$stu_performance_main_category', 
        '$stu_performance_sub_category', 
        '$stu_performance_activity_name', 
        '$stu_performance_activity_date', 
        '$stu_performance_activity_description')"; 
+0

用PK更新了查詢null。但結果是一樣的 –

+0

你使用什麼數據庫驅動程序? PDO還是別的? @SupunDhananjaya –

+0

我該如何檢查?我使用mysql的默認設置。然而,完全相似的查詢在我的其他頁面中使用相同的設置。 –