EasyUI Forum
May 26, 2024, 10:43:39 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Why is my Save not working?  (Read 6047 times)
AJLX
Newbie
*
Posts: 17


View Profile
« 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:

Code:
 <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:
 
Code:
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:

Code:
<?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.'));
}
?>



Logged
AJLX
Newbie
*
Posts: 17


View Profile
« Reply #1 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
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #2 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.
Logged
AJLX
Newbie
*
Posts: 17


View Profile
« Reply #3 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
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #4 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.
Code:
$('#fm').form('submit',{
  iframe: false,
  //...
});
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!