2

I have created a form in HTML and I m trying to post the information in the form to a MySQL database. My form makes use of a dynamic list selection that needs to be captured to the database. However when submitting the form I get the following error

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

Here is my HTML code for the form

    <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)
    ?> 
1
  • 2
    You should seriously check for SQL injections and sanitize your input. See mysql_real_escape_string() for reference. Commented May 27, 2010 at 7:51

4 Answers 4

3

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

Your SQL statement probably refers to a column that does not exist (in your INSERT INTO, probably). Check the real error message for what name you are using.

One remark: it is very dangerous to construct SQL strings like that (from user inputted data) - if a user fills the 'comments' field with test'); DROP TABLE customer_services_tracker; -- your query will become... very evil.

Instead, use prepared statements or atleast escape the user input.

Sign up to request clarification or add additional context in comments.

Comments

0

You should echo out the sql statement by changing die() to die('SQL: '.$sql.' Error:'.mysql_error());

Also, as an aside you should never just put posted variables into a database, who knows what they contain.

Comments

0
  1. You're running not the code you posted here. Save this code into a file and make sure you made this file the actual form's action.

  2. add this code before $sql =...:

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

Comments

0

This error is sometimes caused by incorrect syntax. Try replacing your apostrophes (') with grave accents (`) and adding these to your column names.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.