Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP function ignoring an if statement
    primarykey
    data
    text
    <p>Due to one agent wanting his website url on the functionality that I worked on a month ago I ended up having to make some minor changes. I have two function PHP pages that run a very similar script but I had to make two based of two value sets. What they echo onto the page with AJAX is exactly the same and this is where it gets a little weird...</p> <p>The first script I did was successful but I needed to make a <code>if elseif else</code> statement so everyone agent didn't have a link that went no where. After fiddling around with this statement I was able to get just the one agent to have his website URL on there. Once I had that done I was under the impression that it would be smoothing sailing from there..it was not... </p> <p>I used the exact same statement for both of their scripts and only one works. The only thing that differs from them is what value it is receiving and that I use JavaScript + AJAX for the first one (Which works) and then decided to learn jQuery + AJAX to do the next one. Before this they all worked and it is the exact code for both besides the use of JavaScript/jQuery (which is the same language) and one uses <code>GET</code> while the other uses <code>POST</code></p> <p>I also get no errors or anything while the function is running. The agent's name is Sam Fiorentino that is the only one with a website url. <strong>I went into the console for the second search, the radio buttons, and it shows the company name outside of the anchor tag which is the root of the problem.</strong> Why would one display it correctly while the other doesn't?</p> <p><strong>First PHP</strong> (Works)</p> <pre><code>while ($stmt-&gt;fetch()) { // Gets results from the database echo "&lt;div class='agentcon'&gt;" . "&lt;span class='agentn'&gt;" . "&lt;strong&gt;". $First_Name . "&amp;nbsp;" . $Last_Name . "&amp;nbsp;" . $Suffix . "&lt;/strong&gt;" . "&lt;/span&gt;" . "&lt;a href=mailto:".$Email . "&gt;" . "&lt;span class='email'&gt;" . "Send an e-mail to" . "&amp;nbsp;" . $First_Name . "&lt;/span&gt;" . "&lt;/a&gt;" ."&lt;div class='floathr'&gt;&lt;/div&gt;"; if ($Company == NULL) { echo "&lt;p&gt;"; } elseif ($Website == NULL) { echo "&lt;p&gt;" . "&lt;strong&gt;" .$Company . "&lt;/strong&gt;" . "&lt;br&gt;"; } else { echo "&lt;p&gt;" . "&lt;strong&gt;" . "&lt;a target='blank' href=" .$Website . "&gt;" .$Company . "&lt;/a&gt;" . "&lt;/strong&gt;" . "&lt;br&gt;"; } </code></pre> <p><strong>Second PHP</strong> (Doesn't Work)</p> <pre><code>while ($stmt-&gt;fetch()) { // Gets results from the database echo "&lt;div class='agentcon'&gt;" . "&lt;span class='agentn'&gt;" . "&lt;strong&gt;".$First_Name . "&amp;nbsp;" .$Last_Name . "&amp;nbsp;" . $Suffix . "&lt;/strong&gt;" . "&lt;/span&gt;" . "&lt;a href=mailto:".$Email . "&gt;" . "&lt;span class='email'&gt;" . "Send an e-mail to" . "&amp;nbsp;" .$First_Name . "&lt;/span&gt;" . "&lt;/a&gt;" ."&lt;div class='floathr'&gt;&lt;/div&gt;"; if ($Company == NULL) { echo "&lt;p&gt;"; } elseif ($Website == NULL) { echo "&lt;p&gt;" . "&lt;strong&gt;" .$Company . "&lt;/strong&gt;" . "&lt;br&gt;"; } else { echo "&lt;p&gt;" . "&lt;strong&gt;" . "&lt;a target='blank' href=" .$Website . "&gt;" .$Company . "&lt;/a&gt;" . "&lt;/strong&gt;" . "&lt;br&gt;"; } </code></pre> <p><strong>SQL + Binded code</strong> (First/Working one)</p> <pre><code>$sql="SELECT First_Name, Last_Name, Suffix, Email, Company, WorkAddress1, WorkCity, WorkStateProvince, WorkZipCode, Work_Phone, Fax, Ancillary, SmallGroup, IndividualPlans, LongTermCare, Medicare, LargeGroup, TPASelfInsured, CertifiedForPPACA, Website FROM `roster` WHERE Last_Name = '".$q."' OR Company = '".$q."' OR WorkCity = '".$q."' OR WorkZipCode = '".$q."' ORDER BY Last_Name ASC"; if(!$stmt = $con-&gt;Prepare($sql)) { die; }else{ $stmt-&gt;execute(); $stmt-&gt;store_result(); $stmt-&gt;bind_result($First_Name, $Last_Name, $Suffix, $Email, $Company, $WorkAddress1, $WorkCity, $WorkStateProvince, $WorkZipCode, $Work_Phone, $Fax, $Ancillary, $SmallGroup, $IndividualPlans, $LongTermCare, $Medicare, $LargeGroup, $TPASelfInsured, $CertifiedForPPACA, $Website); $rows = $stmt-&gt;num_rows; </code></pre> <p><strong>SQL + Binded code</strong> (Not working one)</p> <pre><code>$poststr = $_POST['expertise']; //get our post data if(count($poststr) &gt; 1){ //count to make sure we have an array $expertise = implode(" AND ",$_POST['expertise']); //implode the array using AND as glue } else{ //otherwise if it is only one no need for implode $expertise = implode("",array($poststr)); } //here is our string for prepared statement $sql = "SELECT First_Name, Last_Name, Suffix, Email, Company, WorkAddress1, WorkCity, WorkStateProvince, WorkZipCode, Work_Phone, Fax, Ancillary, SmallGroup, IndividualPlans, LongTermCare, Medicare, LargeGroup, TPASelfInsured, CertifiedForPPACA, Website FROM roster WHERE ".$expertise." = 1 ORDER BY Last_Name ASC"; if(!$stmt = $con-&gt;Prepare($sql)) { die; }else{ $stmt-&gt;execute(); $stmt-&gt;store_result(); $stmt-&gt;bind_result($First_Name, $Last_Name, $Suffix, $Email, $Company, $WorkAddress1, $WorkCity, $WorkStateProvince, $WorkZipCode, $Work_Phone, $Fax, $Ancillary, $SmallGroup, $IndividualPlans, $LongTermCare, $Medicare, $LargeGroup, $TPASelfInsured, $CertifiedForPPACA, $Website); $rows = $stmt-&gt;num_rows; </code></pre> <p><strong>Javascript + AJAX</strong> (First one/Working one)</p> <pre><code>&lt;script&gt; function showUser(str) { if (str=="") { document.getElementById("bodyA").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 &amp;&amp; xmlhttp.status==200) { document.getElementById("bodyA").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","process.php?q="+str,true); xmlhttp.send(); } &lt;/script&gt; </code></pre> <p><strong>jQuery + AJAX</strong> (Second one/Not working)</p> <pre><code>$('input').on('click', function() { //Pulls data based on radial input var value = $(this).val(); $.ajax({ type: 'POST', datatype: "html", data: { expertise: value }, url: "expertise.php", success: function (data) { $('#bodyA').html(data); } }); }); </code></pre> <p>Any idea? All help will be greatly appreciated and if you need more code then just let me know!</p> <p>This is also the only time I have ever used PHP so bare with me!</p> <p><a href="http://healthbenefitsohio.com/advance.php" rel="nofollow">Live Site</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    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