I am having the form.php file-

<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="form.js"></script>
</head>
<?
mysql_connect('localhost','root','');
mysql_select_db('test'); 
$query="SELECT * FROM user";
$result=mysql_query($query);

?>
<div id="contact_form">
<form name="contact" action="">
<fieldset>
<label for="txn_unit" id="txn_unit">Txn Unit</label>
<SELECT name="name" id="name">
<OPTION value="">SELECT</OPTION>
<?
while($row=mysql_fetch_assoc($result))
{
?>
<OPTION value="<? echo $row['id']; ?>"><? echo $row['first_name']; ?></OPTION>
<?
}
?>
</SELECT>
<label class="error" for="name" id="name_error">Owner name field is required.</label>

<label for="description" id="desc_label">Description</label>
<input type="text" name="desc" id="desc" size="30" value="" class="text-input">
<label class="error" for="desc" id="desc_error">Description is required.</label>

<label for="income" id="income">Income</label>
<input type="text" name="income" id="income" size="30" value="" class="text-input">
<label class="error" for="income" id="income_error">Income field is required.</label>

<label for="expend" id="expend_label">Expend</label>
<input type="text" name="expend" id="expend" size="30" value="" class="text-input">
<label class="error" for="expend" id="expend_error">Expend field is required.</label>
<label class="error" for="expend" id="combine_error1">In Income and Expend field, one field is required.</label>
<label class="error" for="expend" id="combine_error2">In Income and Expend field, only one field is required.</label>


    <br />  
    <input type="submit" name="submit" class="button" id="submit_btn" value="ok" />
</fieldset>
</form>

And jquery file form.js is-

$(function() {
  $('.error').hide();
  $(".button").click(function(){
     //validate and process from here
      $('.error').hide();

        var name=$("#name").val();
         if(name=""){
         $("label#name_error").show();
         $("input#name").focus();
          return false;
          }

          var income=$("input#income").val();
          var expend=$("input#expend").val();
           if(income!="" && expend!="")
            {
              $("label#combine_error2").show();
              $("input#income").focus();
              $("input#expend").focus();
              return false;
            }

         var description=$("input#desc").val();
         if(description=="")
           {
              $("label#desc_error").show();
              $("input#desc").focus();
              return false;
           }


          if(income=="" && expend=="")
            {
              $("label#combine_error1").show();
              $("input#income").focus();
              $("input#expend").focus();
               return false;
            }


      var dataString='description='+description+'&income='+income+'&expend='+expend+'name='+name;
      $.ajax({
        type: "POST",
        url: "process.php",
        data: dataString,
        success: function() {
          $('#contact_form').html("<div id='message'></div>");
          $('#message').html("<h2>Transaction Saved</h2>")
          .hide()
          .fadeIn(1500,function(){
           $('#message').append("<img id='checkmark' src='images/check.png'/>");
            });
           }
        });
       return false;
    });
});

And finally process.php file-

<?
mysql_connect('localhost','root','');
mysql_select_db('test');
IF(empty($_POST['income']))
  {
      $txn_amount=$_POST['expend'];
      $txn_type='D';
  }
else
  {
      $txn_amount=$_POST['income'];
      $txn_type='C';
  }
$query="INSERT INTO rt_transaction (rt_owner_id,rt_txn_date,rt_txn_desc,rt_txn_amount,rt_txn_type) VALUES('".$_POST['name']."','".strtotime(2013-01-10)."','".$_POST['description']."','".$txn_amount."','".$txn_type."')";
mysql_query($query);

?>

The problem is that the value in column 'rt_owner_id' is not inserting in database.

the value in column 'rt_owner_id' is not inserting in database

I suggest you log/output the query before executing, so you can see what is being inserted. Is it only that value that's missing, or is nothing inserted? What type of table column is it? Any restrictions on it?

is rt_owner_id colunm a primary key and will u give it auto increment?
if u give it auto increament then u have to give null value in query for rt_owner_id colunm

this column type is 'int',and there are no restrictions on it.I have seen the value by alert.it alerts correct value.and rt_owner_id is nither primary key nor autoincrement.

Are you trying to put text data into an INT field? That won't work. If you do:
mysql> SET sql_mode = 'STRICT_ALL_TABLES';
then you should get something like
ERROR 1264 (22003): Out of range value adjusted for column 'rt_owner_id' at row 1
when the php is run.
Can you change the field type to CHAR and add a field of INT for ID?

commented: thank you sir,you have solved my problem +2

Just as a quick note I believe that your HTML locating the jQuery file should go as (Using the http:// to locate the JQuery file:

<script src"http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

Aside from that (and actually answering your question), we are still clueless to why this is happening, so I suggest testing to diagnose the error by:

  1. echo $_POST['name']
  2. mysql_query() or die(mysql_error());

1 so we can see exactly what we are trying to insert and 2 so we can see if mysql has an error message that can solve the problem.

Please reply with what the results are so I can help, sorry to be a pain ;)

the problem was in my process.php file.posting variable was not int.i have changed it to int and then inserted into database.thank you for 'nabcoengineer' to give me idea.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.