10 Replies - 584 Views - Last Post: 31 October 2013 - 01:10 PM

#1 dannybarh  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 19-February 11

make ajax script submit more than one values to mysql

Posted 21 October 2013 - 09:59 AM

Hi all, I have this ajax script that accepts only one value at a time. I want to send more than one value to mysql for processing... but am not so good with javascript, pls point me in the right way....thanks

// auto select vehicle # and fleet #
        <script>
                function showFleet_Loc(str)
                {
                if (str=="")
                  {
                  document.getElementById("fleet_loc_Hint").innerHTML="";
                  return;
                  } 
                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)
                    {
                    document.getElementById("fleet_loc_Hint").innerHTML=xmlhttp.responseText;
                    }
                  }
                xmlhttp.open("GET","fleet_loc_select.php?q="+str,true);
                xmlhttp.send();
                }
             </script>


Here is fleet_loc_select.php


 
<?php
$q=$_GET["q"];
                $cd ="UPDATE vehicles SET image_file='$newimage' WHERE svreg='$q'"; 
                mysql_query($cd);                   
            ?>


Is This A Good Question/Topic? 0
  • +

Replies To: make ajax script submit more than one values to mysql

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3470
  • View blog
  • Posts: 9,972
  • Joined: 08-June 10

Re: make ajax script submit more than one values to mysql

Posted 21 October 2013 - 10:08 AM

for the AJAX side: create a query as you know it, i.e. name1=value1&name2=value2 (etc.)

PHP: retrieve every named URL parameter.
Was This Post Helpful? 0
  • +
  • -

#3 dannybarh  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 19-February 11

Re: make ajax script submit more than one values to mysql

Posted 21 October 2013 - 11:03 AM

You mean like this
xmlhttp.open("GET","fleet_loc_select.php?q="+str+ name1=value1+name2=value2,true);


which then represents the values from my form?

And use

$q=$_GET["q"];

$name1=$_GET["name1"];

$name2=$_GET["name2"];


to retrieve values ??
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3470
  • View blog
  • Posts: 9,972
  • Joined: 08-June 10

Re: make ajax script submit more than one values to mysql

Posted 21 October 2013 - 12:20 PM

View Postdannybarh, on 21 October 2013 - 08:03 PM, said:

You mean like this
xmlhttp.open("GET","fleet_loc_select.php?q="+str+ name1=value1+name2=value2,true);

no. I mean it like demonstrated and how key-value pairs are to be separated in a GET request.
Was This Post Helpful? 1
  • +
  • -

#5 dannybarh  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 19-February 11

Re: make ajax script submit more than one values to mysql

Posted 22 October 2013 - 05:41 AM

can you pls post an example, am abit confused
Was This Post Helpful? 0
  • +
  • -

#6 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3470
  • View blog
  • Posts: 9,972
  • Joined: 08-June 10

Re: make ajax script submit more than one values to mysql

Posted 22 October 2013 - 05:53 AM

"fleet_loc_select.php?q="+str+"&name1=value1&name2=value2"

Was This Post Helpful? 1
  • +
  • -

#7 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3086
  • View blog
  • Posts: 10,319
  • Joined: 12-December 12

Re: make ajax script submit more than one values to mysql

Posted 22 October 2013 - 11:07 AM

I'll just mention that if the querystring has any characters other than alphanumeric then it should be url-encoded. (In principle, it should be url-encoded anyway.)
Was This Post Helpful? 1
  • +
  • -

#8 dannybarh  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 19-February 11

Re: make ajax script submit more than one values to mysql

Posted 31 October 2013 - 12:57 PM

i have this ajax script

<script type="text/javascript"> 
        var url = "GetAutoData.php?svreg="; // The server-side script 
       function handleHttpResponse() {    
        if (http.readyState == 4) { 
              if(http.status==200) { 
                  var results=http.responseText; 
              document.getElementById('divAutoInfo').innerHTML = results; 
              } 
              } 
        } 
        function requestAutoInfo() {      
            var svreg = document.getElementById("getautomobile").value; 
            http.open("GET", url + escape(svreg), true); 
            http.onreadystatechange = handleHttpResponse; 
            http.send(null); 
        } 
function getHTTPObject() { 
  var xmlhttp; 
  if(window.XMLHttpRequest){ 
    xmlhttp = new XMLHttpRequest(); 
  } 
  else if (window.ActiveXObject){ 
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
    if (!xmlhttp){ 
        xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
    } 
} 
  return xmlhttp; 
} 
var http = getHTTPObject(); // We create the HTTP Object 
</script>      


with this html script


Automobile #: <input type="text" id="getautomobile" value="" />
<input type="button" value="Get Automobile Info" onclick="requestAutoInfo()" />
<div id="divAutoInfo"></div> 


Am trying to add a secound field "Automobile #2:<input type="text" id="getautomobile2" value="" />" to the html part and send it to mysql through the above ajax script,but am at a lost.Pls help me out...
Was This Post Helpful? 0
  • +
  • -

#9 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8849
  • View blog
  • Posts: 33,158
  • Joined: 12-June 08

Re: make ajax script submit more than one values to mysql

Posted 31 October 2013 - 12:59 PM

Don't you already have a topic on this?
Was This Post Helpful? 0
  • +
  • -

#10 dannybarh  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 19-February 11

Re: make ajax script submit more than one values to mysql

Posted 31 October 2013 - 01:09 PM

that do not seems to work, pls
Was This Post Helpful? 0
  • +
  • -

#11 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8849
  • View blog
  • Posts: 33,158
  • Joined: 12-June 08

Re: make ajax script submit more than one values to mysql

Posted 31 October 2013 - 01:10 PM

Don't create duplicate topics. Merging.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1