Response title
This is preview!
<html>
<head>
<style type="text/css">
#add(display: none;}
</style>
<script type="text/javascript" src="jquery-1.7.1.js">
</script>
<script type="text/javascript">
$(document).ready(function(){
$("#add_new").click(function(){
$("#add").slideToggle();
});
$("#submit").click(function(){
var stud_no=$("#stud_no").val();
var name=$("#name").val();
if(stud_no==''){
$("#msg").html("Input Student Number");
}
else if(name==''){
$("#msg").html("Input Name");
}
else {
var datastr = 'stud_no='+stud_no + 'name='+name;
$.ajax({
type:'POST',
url:'add_it.php',
data:datastr,
success:function(){
$("#msg").html("Student Successfully Added");
//$("#msg").html("response");
}
});
}
});
});
</script>
</head>
<body>
<a style ="cursor: pointer; color: #0099ff;" id="add_new">+add new item</a><br /><br />
<div id="msg"></div><br />
<div id="add">
<form id="my_form">
Student Number: <input type="text" id="stud_no" name="stud_no" /><br />
Name: <input type="text" id="name" name="name" /><br />
<input type="button" value="submit" id="submit" />
</form>
</div>
</body>
</html>
<?php
include('connectdb.php');
$stud_no=$_POST['stud_no'];
$name=$_POST['name'];
$query = "insert into test (stud_no,name) values ('$stud_no','$name')";
mysql_query($query) or die (mysql_error());
?>
the jquery successfully sends the variable to the php file
the problem is once i insert it into a database all the variables i sent are concatenated
for example in the column stud_no
once you send the form this is what will be inserted
"123123name=asdasd"
i need help
var datastr = 'stud_no=' + stud_no + '&name=' + name;
© 2013 jQuery Foundation
Sponsored by and others.