1 Replies - 3411 Views - Last Post: 06 June 2011 - 04:10 AM

#1 azizknot   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 09-November 09

textarea in form does not submit to mysql (using jquery and ajax

Posted 06 June 2011 - 02:33 AM

Hello,
The code below works fine if i remove the textarea submission method in jquery
If i allow the textarea id with mdesc the whole submission of the form does not work.
I want to know why doenst jquery or ajax allow the last varaiable which is a textarea to be submitted to mysql
Below is the code
<?php require_once("includes/mysql_conn_ceh.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Admin(Add Major)</title>
<link href="style/majorlayout.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-1.6.1.min.js" type="text/javascript"></script>
<script src="js/jquery.validate.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
			$("#major").validate();
			$(".addmajor").click(function() {  
			
    		 var code = $("#mcode").val();
		     var name = $("#mname").val();
			 var type = $("input[@name='mtype']:checked").val();
			 var fac =  $("#mfac").val();
			 var req = $("#mreqs").val();
			 var reqty = $("input[name='mreqsty']:checked").val();
		   	 var descr = $("#mdesc").val();
            if((code != "") && (name != "") && (type == "Bachelor" || type == "Masters" || type == "PHD") && (fac != "") && (req != "") && (reqty == "Credits" || reqty == "Hours"))
					   {
			 $.ajax({  
             type: "POST",  
             url: "majorform.php",  
             data: "mcode="+ code +"& mname="+ name +"& mtype="+ type +"& mfac="+ fac +"& mreqs="+ req +"& mreqsty="+ reqty +"& mdesc="+ descr,  
			 dataType: 'json',
             success: function(data){
				 if(data.success == 'y'){   
                            alert('form submitted');
                        }  
                        else  {  
                            alert('Same Course code already submitted');
                        }     
				 },
			 error: function(data){
				 alert('form not submitted');
			 }
        		   });
					   }
																  
  											});
			$(".clear").click(function() {  
			$("#major").clearform();
			$(".error").remove();
									     });
						   });
</script>
</head>

<body>

<h3>Add/Edit/Delete Major </h3>
<hr />
<form id = "major" name = "major" action="" method="post">
<label for="mcode">Major Code: </label><input type="text" id="mcode" name="mcode" class="required" minlength="1"/>
<hr />
<label for="mname">Major Name: </label><input type="text" id="mname" name="mname" class="required" minlength="5"/>
<label for="mtype">Major Type: </label><input type="radio" id ="mtype" name="mtype"  class="required" value="Bachelor" />Bachelor
<input type="radio" id ="mtype" name="mtype" value="Masters" />Masters
<input type="radio" id ="mtype" name="mtype" value="PHD" />PHD
<hr />
<label for="mfac">Faculty: </label><input type="text" id="mfac" name="mfac" class="required" minlength="1" value =""/>
<hr />
<label for="mreq">Requirements: </label><input type="text" id="mreqs" name="mreqs" class="required" minlength="1" value =""/>
<input type="radio" id ="mreqsty" name="mreqsty"  class="required" value="Credits" />Credits
<input type="radio" id ="mreqsty" name="mreqsty" value="Hours" />Hours
<hr />
<label for="mdesc">Description: </label><textarea id="mdesc" name="mdesc" class="required" minlength="5"></textarea>
<hr />
<input type="submit" class="addmajor"  name="addmajor" value="Add Major" />
<input type="reset" class="clear"  name="clear" value="Clear Form" />
</form>

<?php mysql_close($connection); ?> 
</body>
</html>



and
<?php require_once("includes/mysql_conn_ceh.php");
         
		 
        $code = $_POST['mcode'];  
        $name = $_POST['mname'];  
		$type = $_POST['mtype'];  
        $fac = $_POST['mfac'];  
		$req = $_POST['mreqs'];  
        $reqty = $_POST['mreqsty']; 
		$descr = $_POST['mdesc'];

 $response_object = array('success' => 'y');

    	$res = mysql_query("SELECT code FROM major WHERE code = '$code'");
    	$i_exists = mysql_num_rows($res);

    if( $i_exists == 0 ){
        $msg_code = 'code available';
		$addMajor  = "INSERT INTO major(code, name, major_type, faculty, requirements, requirements_type, description) VALUES ('$code','$name','$type','$fac','$req','$reqty','$descr')";
		 mysql_query($addMajor,$connection) or die(mysql_error());
    	}
    else{
        $response_object['success'] = 'n';
        $msg_code = 'code not avaliable';
   		 }

    $response_object['msg_code'] = $msg_code; 

print json_encode($response_object);


      
?>  



Is This A Good Question/Topic? 0
  • +

Replies To: textarea in form does not submit to mysql (using jquery and ajax

#2 japanir   User is offline

  • jaVanir
  • member icon

Reputation: 1014
  • View blog
  • Posts: 3,025
  • Joined: 20-August 09

Re: textarea in form does not submit to mysql (using jquery and ajax

Posted 06 June 2011 - 04:10 AM

Is th data grabbd from a form?
you can use serialize() instead:
http://api.jquery.com/serialize/

This post has been edited by japanir: 06 June 2011 - 04:13 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1