Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8983577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:52:29+00:00 2026-06-15T20:52:29+00:00

I have one simple html form where the fields can be auto populated by

  • 0

I have one simple html form where the fields can be auto populated by entering ID. its working fine. but, if ID not found in database, it can only return null to the form fields. i was trying to display an error message (can be a pop-up window) saying ID not found! but i failed to do it. here is my code to echo info into the form field:

if (strlen($param) > 0) {
    $result = mysql_query("SELECT * FROM contact 
     WHERE contactid LIKE '$param%'");
    if (mysql_num_rows($result) == 1) {
        while ($myrow = mysql_fetch_array($result)) {
            $agentname = $myrow["contactfullname"];
            $agenttel = $myrow["contacttel"];
            $agentsal = $myrow["contactsalutation"];
            $agentid = $myrow["contactid"];
            $textout .= $agentid . ", " . $agentname . ", " . $agenttel . ", " . $agentsal;
        }
    } else {
        $textout = " , , ," . $param;
    }
}
echo $textout;

here is my ajaxFunction:

function ajaxFunction(e){
    var e=e || window.event;
    var keycode=e.which || e.keyCode;
    if(keycode==13 || (e.target||e.srcElement).value==''){ 
    var http;  // The variable that makes Ajax possible! 

    try{ 
        // Opera 8.0+, Firefox, Safari 
        http = new XMLHttpRequest(); 
    } catch (e){ 
        // Internet Explorer Browsers 
        try{ 
            http = new ActiveXObject("Msxml2.XMLHTTP"); 
        } catch (e) { 
            try{ 
                http = new ActiveXObject("Microsoft.XMLHTTP"); 
            } catch (e){ 
                // Something went wrong 
                alert("Your browser broke!"); 
                return false; 
            } 
        }
    }
 var url = "getagentids.php?param=";
                var idValue = document.getElementById("agid").value;
                var myRandom = parseInt(Math.random()*99999999);  // cache buster
                http.open("GET", "getagentids.php?param=" + escape(idValue) + "&rand=" + myRandom, true);
                http.onreadystatechange = handleHttpResponse;
                http.send(null);

                function handleHttpResponse() {
                    if (http.readyState == 4) {
                        results = http.responseText.split(",");
                        document.getElementById('agfn').value = results[0];
                        document.getElementById('agsal').value = results[1];
                        document.getElementById('agtel').value = results[2];
                        document.getElementById('agid').value = results[3];
                    }
           } 
    }   
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T20:52:30+00:00Added an answer on June 15, 2026 at 8:52 pm
    1. Dont use mysql_* functions, use PDO or Mysqli instead.
    2. take care about $param value
    3. If your query should return 1 result, you can use LIMIT 1 , and also there is no need to use while.

    change this :

    $result = mysql_query("SELECT * FROM contact 
         WHERE contactid LIKE '$param%'");
    if (mysql_num_rows($result) == 1) {
            while ($myrow = mysql_fetch_array($result)) {
    

    to

    $result = mysql_query("SELECT * FROM contact 
         WHERE contactid LIKE '$escaped_param%' LIMIT 1");
    if (mysql_num_rows($result) == 1) {
         $myrow = mysql_fetch_array($result);
    

    4. if you want to show a message on your ajax response, you can use json or …. as an simple example, return this string on error :

    error|" , , ," . $param;
    

    and to check if an error occured on your client :

    var result = "error|anything";
    if(result.substr(0,6) == 'error|')
    {
        alert('An error occured.');
    }
    else
    {
        //do what you need!
    }
    

    Edit :

    function handleHttpResponse() 
    {
        if (http.readyState == 4) 
        {
            results = http.responseText;
            if(results.substr(0,6) == 'error|')
            {
                alert('An error occured.');
            }
            else
            {
                results = results.split(",");
                document.getElementById('agfn').value = results[0];
                document.getElementById('agsal').value = results[1];
                document.getElementById('agtel').value = results[2];
                document.getElementById('agid').value = results[3];
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple HTML Form with one column having a select menu with
This is probably a basic html/css question... I have a simple one-button form that
I am working on simple login form. I have two text fields as user
I have a PHP file with one simple echo function: echo 'アクセスは撥ねりません。'; but when
I have a simple HTML form which consists of radio buttons where user has
I have a complex form that has a static section and one that can
I have a simple form with one input. The page is located here: Actual
I have a simple form all the fields work perfectly and the data is
I have a simple form like this one: <form ENCTYPE=multipart/form-data action=upload.php method=POST> <p>UPLOAD FILE:
I have a simple form with 2 pull-down menus. What I can't figure out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.