How to Post Javascript to a MySQL Database

Posted by salientanimal on Stack Overflow See other posts from Stack Overflow or by salientanimal
Published on 2010-05-27T07:45:53Z Indexed on 2010/05/27 7:51 UTC
Read the original article Hit count: 295

Filed under:

Hi guys,

I have created a form in HTLM and I m trying to post the information in the form to a MySQL database. My form make suse of a dynamic list selection that needs to be captured to the database. However when submtting 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>

Customer Name : E-Mail Address :

    </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)
?> 

© Stack Overflow or respective owner

Related posts about php