-1

I'm back and this one might be a little tricky but we will find out! :D

Okay I am using php to self populate my select fields so I don't have to continuously update the options when new agents join. I am using ajax (javascript) for this part of the page and I have had no problems with this except with the company select field.

Live site

All my select fields work with out any problems but the Company field which will display nothing only on companies that seem to have "&" in the name. (Two companies still work with "&" in the name)

List of non-functioning Companies:
-Anthem
-Bogart
-Burnham
-Church Insurance
-Fawcett
-JRM
-Kenneth B. Brown
-Newton
-Sam F.
-Sherrill
-Wallace & Turner

PHP Company select code: (The if/else statement in the companies field would ideally be if ($row['Company'] !== NULL) { echo '<option value="'.$row['Company'].'">'.$row['Company'].'</option>'; } but for some reason it will echo in a blank space in the option dropdown.)

<label for="company">Company</label><br />
<select id="company" name="users" onChange="showUser(this.value)">
       <?php include 'login.php';

        $result = mysqli_query($con, "SELECT DISTINCT Company FROM `roster` ORDER BY Company ASC;");
                    echo '<option value="">' . 'Select a Company' .'</option>';
                    while ($row = mysqli_fetch_array($result)) {
                        if ($row['Company'] == NULL) {

                        }
                        else {
                            echo '<option value="'.$row['Company'].'">'.$row['Company'].'</option>';
                        }
                    }
        ?>
</select>

PHP for other select fields:

<label for="last">Last Name</label><br />
                <select id="last" name="Last_Name" onChange="showUser(this.value)">
                    <?php include 'login.php';

                    $result = mysqli_query($con, "SELECT DISTINCT Last_Name FROM `roster` ORDER BY Last_Name ASC;");
                    echo '<option value="">' . 'Select an Agent' .'</option>';
                    while ($row = mysqli_fetch_array($result)) {
                        echo '<option value="'.$row['Last_Name'].'">'.$row['Last_Name'].'</option>';
                    }
                    ?>
</select>

Any Ideas on this one? If you need to see the process.php page which echos in the results then just ask! Thanks a million to anyone who helps out.

How the HTML looks when populated through php:

<select id="company" name="users" onchange="showUser(this.value)">
     <option value="">Select a Company</option><option value="A.R.T. Group">A.R.T. Group</option><option value="ALPHA Benefits">ALPHA Benefits</option>                    
</select>

I only included a few since 80ish of them is one massive line of html.

Josh Powell
  • 6,219
  • 5
  • 31
  • 59

1 Answers1

1

You need to urlencode the parameter that is being passed via ajax. The ampersand is telling PHP that $_GET['q'] is complete and a new $_GET variable is starting.

Notice the %26 for the ampersand returns the desired result.

http://healthbenefitsohio.com/process.php?q=Anthem%20Blue%20Cross%20%26%20Blue%20Shield

Your company options should look like this:

echo '<option value="'.urlencode($row['Company']).'">'.$row['Company'].'</option>';

For good measure, I would also encode the display

echo '<option value="'.urlencode($row['Company']).'">'.htmlspecialchars($row['Company'],ENT_QUOTES).'</option>';
  • I will give this a try in just a few minutes and I'm hopping it works! This has been one heck of a learning experience for my first time ever trying php. – Josh Powell Aug 05 '13 at 16:14
  • Hmm This is interesting: process.php?q=Anthem%20Blue%20Cross%20%26%20Blue%20Shield, When I was using the console in Google Chrome It showed these results but it included the "&" symbol. If it displayed it like this I could have clearly seen what was wrong. – Josh Powell Aug 05 '13 at 16:24
  • Google chrome showed the ampesand.. That's how i identified the bug. – user20232359723568423357842364 Aug 05 '13 at 16:27
  • Well I greatly appreciate the help with this and your answer did solve my question. Is there a better console to use so I don't run into this problem again or should I just get familiar with how the browser renders text? I write a lot of html but I was under the impression that & = "&". – Josh Powell Aug 05 '13 at 16:30
  • read up on urlencoding(http://stackoverflow.com/questions/4667942/why-should-i-use-urlencode) and html encoding(http://stackoverflow.com/questions/4882307/when-to-use-htmlspecialchars-function) -- for dev and debug i use firebug and chrome – user20232359723568423357842364 Aug 05 '13 at 16:31
  • Also, your #nav and .navl would look better if you remove the left margins and set widths to 100% – user20232359723568423357842364 Aug 05 '13 at 16:36
  • Oh trust me that design would look a lot better with a million things done to it but I am only allowed to do the development on this and that is how they wanted the nav to be lol. You should have seen the html from who ever designed/developed this before me.http://healthbenefitsohio.com/Old%20HBO/index.html --- What I had to work with – Josh Powell Aug 05 '13 at 16:49