0

Hey anyone can help me with this problem ?

I have this issue with my code, two files:

1 - test.php

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Documento sin título</title>
  <script>

        var url = "getagentids.php?param=";

        function handleHttpResponse() {
        if (http.readyState == 4) {
         results = http.responseText.split(",");
            document.getElementById('formality').value = results[0];
            document.getElementById('fullname').value = results[1];
            document.getElementById('sex').value = results[2];
            document.getElementById('id').value = results[3];
            document.getElementById('joindate').value = results[4];
            document.getElementById('jobtitle').value = results[5];
            document.getElementById('city').value = results[6];
            document.getElementById('typeofsalary').value = results[7];
            document.getElementById('contract_type').value = results[8];
         }
        }


        function getagentids() {
        var idValue = document.getElementById("email").value;
        var myRandom=parseInt(Math.random()*99999999);  // cache buster
        http.open("GET", url + escape(idValue) + "&rand=" + myRandom, true);
        http.onreadystatechange = handleHttpResponse;
        http.send(null);
        }


        function getHTTPObject() {
        var xmlhttp;

        if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
         try {
           xmlhttp = new XMLHttpRequest();
           } catch (e) {
           xmlhttp = false;
           }
          }
          return xmlhttp;
        }


var http = getHTTPObject();

  </script>
</head>

<body>
<form name="schform">
<table bgcolor="#dddddd">
<tbody>
<?php
echo $param;
include '../../../connect.php';

    $db =& JFactory::getDBO();
    $query = "SELECT email FROM dbemployeekpw";
    $db->setQuery($query);
    $result = $db->loadObjectList();
    $email  = $result[0];

echo " <select size='1' name='email' id='email' onChange='getagentids()' required >
<option value=''> Seleccione </option>";
foreach($result as $email)
{
     echo "<option value='".$email->email."'>".$email->email."</option>";
}
echo "</select>"

?>
<tr><td>Formality</td><td><input   id="formality" type="text" name="formality"></td></tr>
<tr><td>Fullname</td><td><input   id="fullname" type="text" name="fullname"></td></tr>
<tr><td>Sex</td><td><input   id="sex" type="text" name="sex"></td></tr>
<tr><td>Id</td><td><input   id="id" type="text" name="id"></td></tr>
<tr><td>Joindate</td><td><input  id="joindate" type="text" name="joindate"></td></tr>
<tr><td>Jobtitle</td><td><input   id="jobtitle" type="text" name="jobtitle"></td></tr>
<tr><td>City</td><td><input   id="city" type="text" name="city"></td></tr>
<tr><td>Typesalary</td><td><input   id="typeofsalary" type="text" name="typeofsalary"></td></tr>
<tr><td>Contract Type</td><td><input   id="contract_type" type="text" name="contract_type"> </td></tr>

<tr><td><input size="60"  type="reset" value="Clear"></td><td></td>
</tr>
</tbody></table>
</form>
</body>
</html>

and.. 2 - getagentids.php

<?php 
//$param = $_GET["param"];
include '../../../connect.php';

    $db =& JFactory::getDBO();
    $query = $db->getQuery(true);
    $query = "SELECT * FROM dbemployeekpw WHERE email = 'camilo.uribe@kantarworldpanel.com'";
    $db->setQuery($query);
    $results = $db->loadObjectList();

foreach ( $results as $result )
{
    $formality = $result->formality;
    $fullname = $result->fullname;
    $sex = $result->sex;
    $id = $result->id;
    $joindate = $result->joindate;
    $jobtitle = $result->jobtitle;
    $city = $result->city;
    $typeofsalary = $result->typeofsalary;
    $contract_type = $result->contract_type;    
    $textout = $formality.",".$fullname.",".$sex.",".$id.",".$joindate.",".$jobtitle.",".$city.",".$typeofsalary.",".$contract_type;
}

echo $textout;                  


?>

But ajax dont works, only works if I put this :

    $query = "SELECT * FROM dbemployeekpw WHERE email = 'camilo.uribe@kantarworldpanel.com'";

instead this:

    $query = "SELECT * FROM dbemployeekpw WHERE email = '".$param."'";

But I need that the code works with second one :(

Anyone can help me with this problem ?

Thanks !!

SOLVED (works like a charm!!):

I change this:

$jinput = JFactory::getApplication()->input;
$param = $jinput->get('param', 'param', 'filter');

instead this:

$param = $_GET["param"];

and I'm still with:

  $query = "SELECT * FROM dbemployeekpw WHERE email = '".$param."'";

because this code don't works for me:

$query->select($db->quoteName('*'))
 ->from($db->quoteName('dbemployeekpw'))
 ->where($db->quoteName('email') . ' = '. $db->quote($param));

Many Thanks @lodder

1 Answers1

0

Before anything, lets see if the $param variable is correct and gets the value. Add the following which one the form is processed, will display the value. If the result is NULL then you firstly need to ensure you get the correct value. If you do get the correct value, then carry on reading.

Just on a side note, I would recommend looking at the following link rather than using $_GET:

http://docs.joomla.org/Retrieving_request_data_using_JInput

Lets now use up to date coding standards for you database query:

$db = JFactory::getDbo();
$query = $db->getQuery(true);

$query->select($db->quoteName('*'))
 ->from($db->quoteName('dbemployeekpw'))
 ->where($db->quoteName('email') . ' = '. $db->quote($param));

$db->setQuery($query);
$results = $db->loadObjectList();

Hope this helps

Lodder
  • 19,758
  • 10
  • 59
  • 100