Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-27-2011, 10:58 PM   PM User | #1
mxbikerider
New Coder

 
Join Date: Oct 2010
Posts: 21
Thanks: 1
Thanked 0 Times in 0 Posts
mxbikerider is an unknown quantity at this point
Trying to send URL values to .php file.

Problem: I have a javascript onClick that runs a .php file behind the scenes using ajax xmlhttp.open. My php file doesn't see the values stored in the URL where the onClick link exists.

Question: How do I send URL values so my .php file can update mysql database with those values?

Code:

My url looks like: index.php?id=1&test=hello
My javascript:

<script type="text/javascript">
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {

    }
  }
xmlhttp.open("GET","bar_next.php",false);
xmlhttp.send();
}
</script>





My bar_next.php File



<?php
mysql_query("UPDATE members SET visited = CONCAT($_GET['id'],visited)
WHERE username = '$_COOKIE[user]'");

?>
mxbikerider is offline   Reply With Quote
Old 03-27-2011, 11:20 PM   PM User | #2
bullant
Banned

 
Join Date: Feb 2011
Posts: 2,699
Thanks: 13
Thanked 395 Times in 395 Posts
bullant is on a distinguished road
If you send the ajax request as a GET then you need to append any paramaters to the url ajaxPbj.open(). If you want to send the request as a POST then you send the parameters in the ajaxObj.send() plus you would need to add a few extra lines of code.

AJAX tutorial
bullant is offline   Reply With Quote
Old 03-27-2011, 11:28 PM   PM User | #3
mxbikerider
New Coder

 
Join Date: Oct 2010
Posts: 21
Thanks: 1
Thanked 0 Times in 0 Posts
mxbikerider is an unknown quantity at this point
What would the coding look like? If you have the time...
mxbikerider is offline   Reply With Quote
Old 03-27-2011, 11:56 PM   PM User | #4
bullant
Banned

 
Join Date: Feb 2011
Posts: 2,699
Thanks: 13
Thanked 395 Times in 395 Posts
bullant is on a distinguished road
The tutorial on the other side of the link I posted gives example code.
bullant is offline   Reply With Quote
Old 03-28-2011, 12:10 AM   PM User | #5
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
Quote:
Originally Posted by mxbikerider View Post
What would the coding look like? If you have the time...
try this:

http://www.xul.fr/en-xml-ajax.html#ajax-post

http://www.xul.fr/en-xml-ajax.html

best regards
oesxyl is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:26 PM.


Advertisement
Log in to turn off these ads.