Note that there are some explanatory texts on larger screens.

plurals
  1. POAJAX issues when trying to print out MySQL Query
    primarykey
    data
    text
    <p>I'm currently learning AJAX and I've run into this error in which results from MySQL query is not being displayed.</p> <p>The following snippet is of the javascript : </p> <pre><code>&lt;script type="text/javascript"&gt; function showCustomers() { var zip = document.getElementById('zipcode').value; var st = document.getElementById('stname').value; if ((zip=="")&amp;&amp;(st=="")){ document.getElementById("showCustResults").innerHTML=""; return; } mlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200){ document.getElementById("showCustResults").innerHTML=xmlhttp.responseText; } } var querystring = "?zip" + zip + "&amp;st" + st ; xmlhttp.open("POST","findCustomers.php" + querystring, true); xmlhttp.send(); } </code></pre> <p></p> <p>The following is the form in which the information is being pulled from :</p> <pre><code>&lt;form id="search_customers" class="appnitro" method="post" action=""&gt; &lt;ul&gt; &lt;li id="li_2" &gt; &lt;label class="description" for="zipcode"&gt;Zip Code &lt;/label&gt; &lt;div&gt;&lt;input id="zipcode" name="zip_code" class="element text small" type="text" maxlength="10" value=""/&gt; &lt;/div&gt; &lt;p class="guidelines" id="guide_2"&gt;&lt;small&gt;Please enter a Zip Code&lt;/small&gt;&lt;/p&gt; &lt;/li&gt; &lt;li id="li_1" &gt; &lt;label class="description" for="stname"&gt;Street Name &lt;/label&gt; &lt;div&gt;&lt;input id="stname" name="st_name" class="element text medium" type="text" maxlength="50" value=""/&gt;&lt;/div&gt; &lt;p class="guidelines" id="guide_1"&gt;&lt;small&gt;Please Enter the Street Name&lt;/small&gt;&lt;/p&gt; &lt;/li&gt; &lt;li class="buttons"&gt; &lt;input id="findCust" class="button_text" onclick="showCustomers()" type="submit" name="find"/&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/form&gt; &lt;div id="showCustResults"&gt;&lt;!-- Eventually search results will appear here --&gt;&lt;/div&gt; </code></pre> <p>And the PHP that is pulling the cod is the following: </p> <pre><code>&lt;?php include 'functions.php'; #Library that holds all the functions #Sanitizing strings for SQL entry $zip = mysqli_real_escape_string($db, $_POST['zip']); $st = mysqli_real_escape_string($db, $_POST['st']); $db = db_connect(); #Connecting to the database #Querying the database to find any matches #ALSO: We might need to add another column to $sql = "SELECT CustomerName, ServiceAddress, BillingAddress FROM enrollment_users WHERE UserName = '$username' AND Password = '$password'"; $res = mysqli_query($db, $sql); #Creating the table to shoot out the information #First the header... echo "&lt;table border='1'&gt;"; echo " &lt;tr&gt;"; echo " &lt;th&gt;Customer&lt;/th&gt;"; echo " &lt;th&gt;Address 1&lt;/th&gt;"; echo " &lt;th&gt;Address 2&lt;/th&gt;"; echo " &lt;th&gt;Status&lt;/th&gt;"; echo " &lt;/tr&gt;"; #Now the actualy information while($row = mysqli_fetch_assoc($res)){ echo " &lt;tr&gt;"; echo " &lt;td&gt;" . $row['CustomerName'] . "&lt;/td&gt;"; echo " &lt;td&gt;" . $row['ServiceAddress'] . "&lt;/td&gt;"; echo " &lt;td&gt;" . $row['BillingAddress'] . "&lt;/td&gt;"; echo " &lt;td&gt;&lt;/td&gt;"; } echo"&lt;/table&gt;"; db_close($db); #Closing the database </code></pre> <p>?></p> <p>I've been trying to figure this out for the past day with no avail. Hopefully someone can see what I cannot. </p> <p>Thanks ahead. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload