我创建了一个HTML表单,我也编写了PHP脚本来连接数据库。如果我在表单中输入数据并在表单中点击UPDATE按钮,则显示错误如下,
<form action="process.php" method="Post"/>
<style>
p{
float:left;
}
</style>
<fieldset>
<legend align="center"><FONT color=default>Enter information Of SO's</legend>
<p align="center">
<label for="SO_ID"><FONT color=white>SO_ID</label>
<br/>
<input type="varchar" id="SO_ID" name="SO_ID"required/>
</p>
<p align="center">
<label for="No.of_samples"><FONT color=white>No.of samples</label>
<br/>
<input type="int" id="No.of_samples" name="No.of_samples"required/>
</p>
<p align="center">
<label for="Sample name"><FONT color=white>Sample name</label>
<br />
<input type="varchar" id="Sample name" name="Sample name"required/>
</p>
<p align="center">
<label for="Client name"><FONT color=white>Client name</label>
<br />
<input type="text" id="Client name" name="Client name"required/>
</p>
<p align="center">
<label for="Institution"><FONT color=white>Institution</label>
<br/>
<input type="text" id="Institution" name="Institution"required/>
</p>
<p align="center">
<label for="Run number "><FONT color=white>Run number </label>
<br/>
<input type="int" id="Run number" name="Run number"required/>
</p>
<p align="center">
<label for="Obtained reads"><FONT color=white>Obtained reads</label>
<br/>
<input type="int" id="Obtained reads" name="Obtained reads"required/>
</p>
<p align="center">
<label for="Re run Info"><FONT color=white>Re run Info</label>
<br/>
<input type="text" id="Re run Info" name="Re run Info"required/>
</p>
<p align="center">
<label for="Total reads"><FONT color=white>Total reads</label>
<br/>
<input type="int" id="Total reads" name="Total reads"required/>
</p>
<p align="center">
<label for="Run date"><FONT color=white>Run date</label>
<br/>
<input type="date" id="Run date" name="Run date"required/>
</p>
<p align="center">
<label for="Raw data location"><FONT color=white>Raw data location</label>
<br/>
<input type="varchar" id="Raw data location" name="Raw data location"required/>
</p>
<p align="center">
<label for="Analyst"><FONT color=white>Analyst</label>
<br/>
<input type="varchar" id="Analyst" name="Analyst"required/>
</p>
<p align="center">
<label for="Mentor"><FONT color=white>Mentor</label>
<br/>
<input type="text" id="Mentor" name="Mentor"required/>
</p>
<p align="center">
<label for="Analysis start date"><FONT color=white>Analysis start date</label>
<br/>
<input type="date" id="Analysis start date" name="Analysis start date"required/>
</p>
<p align="center">
<label for="Analysis end date"><FONT color=white>Analysis end date</label>
<br/>
<input type="date" id="Analysis end date" name="Analysis end date"required/>
</p>
<p align="center">
<label for="Report location"><FONT color=white>Report location</label>
<br/>
<input type="varchar" id="Report location" name="Report location"required/>
</p>
</fieldset>
<div style="text-align:center">
<button action= "process.php" method="post" >
<img alt="ok" src=
"http://www.blueprintcss.org/blueprint/plugins/buttons/icons/tick.png" />
UPDATE
</button>
</form>
上述脚本保存在“process.html”
中现在低于PHP脚本。
<?php
define('DB_NAME','ProcessTrackingSystem');
define('DB_USER','root');
define('DB_PASSWORD','');
define('DB_HOST','localhost');
$link=mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
if(!$link){
die('couldnot connect:'.mysql_error());
}
$db_selected=mysql_select_db(DB_NAME,$link);
if(!$db_selected){
die('cannot use'.DB_NAME.':'.mysql_error());
}
$value1 =$_POST['SO_ID'];
$value2 =$_POST['No.of samples'];
$value3 =$_POST['Sample name'];
$value4 =$_POST['Client name'];
$value5 =$_POST['Institution'];
$value6 =$_POST['Run number '];
$value7 =$_POST['Obtained reads'];
$value8 =$_POST['Re run Info'];
$value9 =$_POST['Total reads'];
$value10 =$_POST['Run date'];
$value11 =$_POST['Raw data location'];
$value12 =$_POST['Analyst'];
$value13 =$_POST['Mentor'];
$value14 =$_POST['Analysis start date'];
$value15 =$_POST['Analysis end date'];
$value16 =$_POST['Report location'];
$sql="INSERT INTO ProcessDetails (SO_ID, No.of_samples, Sample_name, Client_name, Institution, Run_number, Obtained_reads, Re_run_Info, Total_reads, Run_date, Raw_data_location, Analyst, Mentor, Analysis_start_date, Analysis_end_date, Report_location) VALUES ('$value1', '$value2', '$value3', '$value4', '$value5','$value6', '$value7', '$value8', '$value9', '$value10','$value11', '$value12', '$value13', '$value14', '$value15','$value16')";
if(!mysql_query($sql)){
die('error:'.mysql_error());
}
header('Location:process.html');
mysql_close();
?>
现在,如果我将数据输入到html表单中,则显示错误“错误:'字段列表'中的未知列'No.of_samples'”。 任何人帮助我解决这个错误并获得所需的输出 提前谢谢....
答案 0 :(得分:3)
假设您的表中存在var obj = {};
var id = obj.id;
//global object
$.when(callone(obj)).then(calltwo(id),function(data)
{
});
列,请在查询中引用带反引号(`)的名称:
function callone(requiredData)
{
var d = new $.Deferred();
var ajaxCall1 = $.ajax({
type:"POST",
url: 'AB/',
data: requiredData,
success: function(data) {
//return data to the callee?
d.resolve(p_obj);
//set ID on the object
obj.id = data.id;
return obj;
},
error: function(jqXHR, textStatus, errorThrown) {
alert(textStatus + ': ' + errorThrown);
},
always: function(data) { }
});
}
function calltwo(id from callback one)
{
}
此外,您可能希望查看SQL注入安全风险,并使用未弃用的No.of_samples
函数而不是已弃用的$sql="INSERT INTO ProcessDetails (SO_ID, `No.of_samples`, Sample_name, Client_name, Institution, Run_number, Obtained_reads, Re_run_Info, Total_reads, Run_date, Raw_data_location, Analyst, Mentor, Analysis_start_date, Analysis_end_date, Report_location) VALUES ('$value1', '$value2', '$value3', '$value4', '$value5','$value6', '$value7', '$value8', '$value9', '$value10','$value11', '$value12', '$value13', '$value14', '$value15','$value16')";
函数。
答案 1 :(得分:2)
您要插入不存在的 No.of_samples 列