Title: Why is my Save not working?
Post by: AJLX on November 09, 2016, 02:48:34 PM
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.')); } ?>
Title: Re: Why is my Save not working?
Post by: AJLX on November 12, 2016, 03:19:36 AM
Anyone? I have ruled out the php file, so I'm guessing it's something to do with the Java function. I've tried deleted and changing it lots, but still can't find a solution. As I said before- I guess it's something simple!
Thanks
AJLX
Title: Re: Why is my Save not working?
Post by: stworthy on November 12, 2016, 06:19:02 PM
Is your url correct? Does the post request reach your server script? Please check your php code carefully.
Title: Re: Why is my Save not working?
Post by: AJLX on November 13, 2016, 01:31:20 AM
Thanks for replying, Just to make things clear, this isn't for a commercial product, it's just a little project in my spare time. If I use hard variables in my php code, instead of the $_REQUEST ones, then it works. So the SQL statement appears to be correct.
If I have a hidden field in my form, and give it a hard "value" it seems to work, but if I give any of the other fields a value, then they don't seem to make it through.
Interestingly, If I add an action to the form code, and then a submit button, the button doesn't seem to work either?
When I click the save button, it adds a blank row to the Db, so I think they're communicating, and there is something either in the form, or the js code that is stopping it.
Thanks guys
Title: Re: Why is my Save not working?
Post by: stworthy on November 13, 2016, 09:40:34 PM
Please try to set the 'iframe' property to false. Open the browser's debug tool to see if the form data posted to server is correct. $('#fm').form('submit',{ iframe: false, //... });
|