2010-05-27 65 views
2

我已經在HTML中創建了一個表單,並且我試圖將表單中的信息發佈到MySQL數據庫。我的表單利用了需要捕獲到數據庫的動態列表選擇。但是,當提交表單時,出現以下錯誤:如何將Javascript發佈到MySQL數據庫

錯誤:'字段列表'中的未知列'coulmn_name'。

這裏是形式

<td height="94"><p align="justify">CALL TRACKER - ADMIN</p></td> 
    </tr> 
    <tr> 
    <td> 
    <table width="36%" border="0" align="center" cellpadding="2" cellspacing="0"> 
     <tr> 
     <td width="29%" align="right" valign="middle"><strong>Customer Name :</strong></td> 
     <td> 
     <input type="text" name="customer_name" width="70%" align="left" valign="middle"> 
     </td> 
     </tr> 
     <tr> 
     <td width="29%" align="right" valign="middle"><strong>E-Mail Address :</strong></td> 
     <td> 
     <input type="text" name="customer_email_address" width="70%" align="left" valign="middle"> 
     </td> 

     </tr> 
     <tr> 
     <td width="29%" align="right" valign="middle"><strong>Case Number :</strong></td> 
     <td> 
     <input type="text" name="case_number" width="70%" align="left" valign="middle"> 
     </td> 
     </tr> 

     <tr> 
     <td width="29%" align="right" valign="middle"><strong>MSISDN :</strong></td> 
     <td> 
     <input type="text" name="msisdn" width="70%" align="left" valign="middle"> 
     </td> 
     </tr> 

     <tr>  
     <td width="29%" align="right" valign="middle"> 
     <strong>Route Cause :</strong></td> 
     <td width="71%" align="left" valign="middle"> 
     <select name="route_cause" id="category" onChange="javascript: listboxchange1(this.options[this.selectedIndex].value);"> 
       <!-- <select name="route_cause" id="route_cause"> --> 
      <option value="">Select the Call Reason</option> 
      <option value="Billing Admin">Billing Admin</option> 
      <option value="Customer Care">Customer Care</option> 
      <option value="Insurance">Insurance</option> 
      <option value="Repairs">Repairs</option> 
      <option value="SIM Swap">SIM Swap</option> 
      <option value="UTI">UTI</option> 

     </select> 
     </td> 
     </tr> 



    <tr> 
     <td align="right" valign="middle"> 
     <strong>Call Type/Indexed To :</strong></td> 
     <td align="left" valign="middle"> 
     <script type="text/javascript" language="javascript" name="calltype_indexedto"> 
       <!-- 
        document.write('<select name="subcategory1" onChange="javascript: listboxchange2(this.options[this.selectedIndex].value);"><option value=""></option></select>') 
        --> 
     </script> 
     </td> 



    </tr> 




    <tr> 
     <td align="right" valign="middle"> 
     <strong>Type/TAT :</strong></td> 
     <td align="left" valign="middle"> 
     <script type="text/javascript" language="javascript" name="type_tat"> 
       <!-- 
        document.write('<select name="subcategory2" onChange="javascript: listboxchange3(this.options[this.selectedIndex].value);"><option value=""></option></select>') 
        --> 
     </script> 
     </td> 



    </tr> 



    <tr>  
    <td width="29%" align="right" valign="middle"> 
     <strong>Escalated To :</strong></td> 
     <td width="71%" align="left" valign="middle"> 
     <select name="escalatedto" id="escalated_to"> 
      <option value="">Select the Escalation</option> 
      <option value="Billing Ops">Billing Ops</option> 
      <option value="Resolvers">Resolvers</option> 
      <option value="Finance">Finance</option> 
      <option value="Ressolver">Ressolver</option> 
      <option value="Nudebt">Nudebt</option> 
      <option value="Transunion">Transunion</option> 
      <option value="N/A">N/A</option> 


     </select> 
     </td> 
     </tr> 


     <tr>  
    <td width="29%" align="right" valign="middle"> 
     <strong>Requested By :</strong></td> 
     <td width="71%" align="left" valign="middle"> 
     <select name="requestedby" id="requested_by"> 
      <option value="">UTI Requested By</option> 
      <option value="Billing">Billing</option> 
      <option value="Customer Service">Customer Service</option> 
      <option value="Insurance">Insurance</option> 
      <option value="Management">Management</option> 
      <option value="Repairs">Repairs</option> 
      <option value="Retail Support">Retail Support</option> 
      <option value="Retentions">Retentions</option> 
      <option value="SIM Swap">SIM Swap</option> 
      <option value="WOW">WOW</option> 
      <option value="N/A">N/A</option> 


     </select> 
     </td> 
    </tr> 


    <tr>  
    <td width="29%" align="right" valign="middle"> 
     <strong>Province :</strong></td> 
     <td width="71%" align="left" valign="middle"> 
     <select name="province" id="province"> 
      <option value="">Select the Province</option> 
      <option value="Eastern Cape">Eastern Cape</option> 
      <option value="Gauteng">Gauteng</option> 
      <option value="Kwa-Zulu Natal">Kwa-Zulu Natal</option> 
      <option value="Limpopo">Limpopo</option> 
      <option value="Mpumalanga">Mpumalanga</option> 
      <option value="North West">North West</option> 
      <option value="Northern Cape">Northern Cape</option> 
      <option value="Polokwane">Polokwane</option> 
      <option value="Western Cape">Western Cape</option> 
      <option value="Other">Other</option> 
     </select> 
     </td> 
     </tr> 

     <tr> 
     <td width="29%" align="right" valign="middle"><strong>Comments :</strong></td> 
     <td> 
     <textarea rows ="5" cols="30" name="comments"> 
     </textarea> 
     </td> 
     </tr> 


     <tr> 
     <td> 
     <p> 
      <input type="reset" value="Reset Form"><input type="Submit" value="Submit"> 

Here is my PHP code to write to the Database 



    <?php 
    $con = mysql_connect("hostname" 
    ,"mysqusername" 
    ,"mysqlpassword"); 
    if (!$con) 
     { 
     die('Could not connect: ' . mysql_error()); 
     } 

    mysql_select_db("databasename", $con); 

    $sql="INSERT INTO customer_services_tracker 
    (customer_name 
    ,customer_email_address 
    ,case_number 
    ,msisdn 
    ,route_cause 
    ,calltype_indexedto 
    ,type_tat 
    ,escalatedto 
    ,requestedby 
    ,province 
    ,comments 
    ) 

    VALUES 
    ('$_POST[customer_name]' 
    ,'$_POST[customer_email_address]' 
    ,'$_POST[case_number]' 
    ,'$_POST[msisdn]' 
    ,'$_POST[route_cause]' 
    ,'$_POST[calltype_indexedto]' 
    ,'$_POST[type_tat]' 
    ,'$_POST[escalatedto]' 
    ,'$_POST[requestedby]' 
    ,'$_POST[province]' 
    ,'$_POST[comments]')"; 

    $CatName = $rowCat["Name"]; 

    if (!mysql_query($sql,$con)) 
     { 
     die('Error: ' . mysql_error()); 
     } 
    echo "1 record added"; 

    mysql_close($con) 
    ?> 
+2

您應該認真檢查SQL注入並清理輸入。請參閱mysql_real_escape_string()以供參考。 – halfdan 2010-05-27 07:51:54

回答

0

你應該通過改變模具回聲出sql語句我的HTML代碼()死亡( 'SQL:' $ sql中 '錯誤:'。mysql_error()。 );另外,作爲一邊,你絕不應該只是把張貼的變量放到數據庫中,誰知道它們包含什麼。

3

Error: Unknown column 'coulmn_name' in 'field list'.

你的SQL語句可能是指列不存在(在你的INSERT INTO,可能)。檢查真實的錯誤消息,查看您正在使用的名稱。

一個說法:構建這樣的SQL字符串是非常危險的(來自用戶輸入的數據) - 如果用戶用test'); DROP TABLE customer_services_tracker; --填充了「註釋」字段,您的查詢將變得非常邪惡。

而是使用準備好的語句或至少逃避用戶輸入。

0
  1. 您正在運行的不是您在此處發佈的代碼。將此代碼保存到一個文件中,並確保您將該文件作爲實際表單的操作。

  2. $sql =...之前添加以下代碼:

    foreach ($_POST as $key => $value) $_POST[$key] = mysql_real_escape_string($value);

0

此錯誤有時是由不正確的語法造成的。嘗試用嚴重口音(')替換您的撇號(')並將其添加到列名稱中。

相關問題