how to send variable using jquery/ajax to a php file and insert it to database?

hi
i am trying to create a form that where the page will not refresh if the form is submitted specially if the user inputs any errors in the form

my problem is i do not know how to send multiple variables using jquery to a php file
i saw somewhere that in order to do this you need to concatenate the variables you will be sending
this is the code i am using

[code]

#add(display: none;} +add new item


Student Number:
Name:
[/code]

and this is the php file where i send my variables
[php]<?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());

?>

[/php]

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

for submitting form using ajax you have to pass all form value in query string and these values must concatenating with ‘&’. if you are tring to submit more than one value.
[php]
/* for submitting form using ajax you have to pass all form value in query string and these values must concatenating with ‘&’ as i did below. if you are tring to submit more than one value. */
//your code need to replace
var datastr = ‘stud_no=’+stud_no + ‘name=’+name;
//with
var datastr = ‘stud_no=’+stud_no + ‘&name=’+name;
[/php]

i hope it’s will helpful for you.
Replay back with your feedback
SR
Reply back

Sponsor our Newsletter | Privacy Policy | Terms of Service