Jump to content

Recommended Posts

I have a simple form

 

<form name=myForm>

<input type="text" name="username" />

<input type="submit" value=Submit />

</form>

 

<?PHP

if(isset($_POST['submit'])){

$username=$_POST['username'];

$fields = array(username);

$values = array($username);

$db->insert($fields,$values,'customer');

echo "data added";

}

?>

 

I want to insert data to database table using POST method. How do i do that using ajax?

 

 

Link to comment
https://forums.phpfreaks.com/topic/80915-how-to-post-using-ajax/
Share on other sites

  • 4 weeks later...

You might want to consider using the Prototype JavaScript framework. Get it here: http://www.prototypejs.org

 

They also have a guide on using AJAX so read up on that. It will make things a lot easier since you don't need to worry about different browsers using different protocols.

I have a simple form

 

<form name=myForm>

<input type="text" name="username" />

<input type="submit" value=Submit />

</form>

 

<?PHP

if(isset($_POST['submit'])){

$username=$_POST['username'];

$fields = array(username);

$values = array($username);

$db->insert($fields,$values,'customer');

echo "data added";

}

?>

 

I want to insert data to database table using POST method. How do i do that using ajax?

 

 

 

Hi,

 

Making AJAX POST request is very easy if you are aware of simple ajax stuff.

 

    http_request = new XMLHttpRequest(); //XMLHttpRequest method has to be defined to create xmlHttprequest

    http_request.onreadystatechange = function() {s=alertContents(http_request)};

    frmstr='name=priti?age=25&gender=f&job=yes&designation=developer';

    http_request.open('POST', "./tests.php", true);

    http_request.send(frmstr);

 

And if you don't want to use this go for jquery ajax.It is easy and smooth.

 

regards

  • 3 months later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.