Hi guys, I have the following code but for some reason it's not saving. I think whatever is wrong is super simple! I some test fields through by adding a value="something" onto each of the inputs, and that seems to work.
The form:
<form id="fm" method="post" novalidate>
<div class="fitem">
<label>Unit Number:</label>
<input name="projectID" type="hidden" class="easyui-textbox" value="<?php echo $project_id;?>" >
<input name="unit" class="easyui-textbox" >
</div>
<div class="fitem">
<label>Address:</label>
<input name="address" class="easyui-textbox" >
</div>
<div class="fitem">
<label>Contents 1:</label>
<input name="contents1" class="easyui-textbox">
</div>
<div class="fitem">
<label>Contents 2:</label>
<input name="contents2" class="easyui-textbox">
</div>
<div class="fitem">
<label>Contents 3:</label>
<input name="contents3" class="easyui-textbox">
</div>
<div class="fitem">
<label>Contents 4:</label>
<input name="contents4" class="easyui-textbox">
</div>
<div class="fitem">
<label>Position Name:</label>
<input name="position" class="easyui-textbox" >
</div>
</form>
This is the Java function:
function saveItem(){
$('#fm').form('submit',{
url: url,
onSubmit: function(){
return $(this).form('validate');
},
success: function(result){
var result = eval('('+result+')');
if (result.errorMsg){
$.messager.show({
title: 'Error',
msg: result.errorMsg
});
} else {
$('#item').dialog('close'); // close the dialog
$('#dg').datagrid('reload'); // reload the item data
}
}
});
}
This is the PHP file:
<?php
$project = htmlspecialchars($_REQUEST['projectID']);
$unit = htmlspecialchars($_REQUEST['unit']);
$address = htmlspecialchars($_REQUEST['address']);
$contents1 = htmlspecialchars($_REQUEST['contents1']);
$contents2 = htmlspecialchars($_REQUEST['contents2']);
$contents3 = htmlspecialchars($_REQUEST['contents3']);
$contents4 = htmlspecialchars($_REQUEST['contents4']);
$position = htmlspecialchars($_REQUEST['position']);
$conn = @mysql_connect('XXXXXXX','XXXXXX','XXXXXX');
mysql_select_db('XXXXX', $conn);
$sql = "insert into pal_label(project_id,unit_no,address,contents1,contents2,contents3,contents4,stage_position) values('$project','$unit','$address','$contents1','$contents2','$contents3','$contents4','$position')";
$result = @mysql_query($sql);
if ($result){
echo json_encode(array(
'row_id' => mysql_insert_id(),
'project_id' => $project,
'unit_no' => $unit,
'address' => $address,
'contents1' => $contents1,
'contents2' => $contents2,
'contents3' => $contents3,
'contents4' => $contents4,
'stage_position' => $position,
));
} else {
echo json_encode(array('errorMsg'=>'Some errors occured.'));
}
?>