我已經在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)
?>
您應該認真檢查SQL注入並清理輸入。請參閱mysql_real_escape_string()以供參考。 – halfdan 2010-05-27 07:51:54