Note that there are some explanatory texts on larger screens.

plurals
  1. POProblems with special characters in my dynamic dropdown
    primarykey
    data
    text
    <p>I've created a dynamic dropdown using JS/PHP/MySQL but it seems I'm having some problems with special characters. The script is going to be used to make a small application that helps my customers find a product that meets their criteria. We sell panel meters that can accept different ranges of input and many are denoted with a +/- or a value (example: a meter can expect to process a voltage +/- 10V around a specified voltage.) Everything is starting to work great in my script except when some characters are parsed through (+, / , ±, ½, etc.) My database originally used ± to denote plus or minus but I then switched to +/- (three characters) in hopes that it would fix the special character problem but it didn't... Also when using ± the character would should up as an unknown character (so somewhere I have my encoding set wrong as well.)</p> <p>So now I still need to figure out why some things are not parsing right.</p> <p>You can view a live version of the script at <a href="http://new.foxmeter.com/find.php" rel="nofollow" title="find.php">http://new.foxmeter.com/find.php</a></p> <p>This is the important part of my frontend </p> <pre><code> &lt;script src="http://code.jquery.com/jquery-latest.min.js"&gt;&lt;/script&gt; &lt;script&gt; $(function(){ $("#type").change(function() { var tval = document.getElementById('type').value; $("#range").load(encodeURI("findbackend.php?type=" + tval)); }); $("#range").change(function() { rval = document.getElementById('range').value; $("#power").load(encodeURI("findbackend.php?range=" + rval)); }); $("#power").change(function() { //var rval = document.getElementById('range').value; psval = document.getElementById('power').value; $("#setpoint").load(encodeURI("findbackend.php?range=" + rval + "&amp;power=" + psval)); }); $("#setpoint").change(function() { //var rval = document.getElementById('range').value; //var psval = document.getElementById('power').value; stval = document.getElementById('setpoint').value; $("#output").load(encodeURI("findbackend.php?range=" + rval + "&amp;power=" + psval + "&amp;setpoint=" + stval)); }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;!-- Google Analytics Script --&gt; &lt;?php include_once("scripts/analyticstracking.php") ?&gt; &lt;div class="wrapper"&gt; &lt;!-- Sticky Footer Wrapper --&gt; &lt;div id="panorama"&gt;&lt;/div&gt; &lt;div id="header"&gt; &lt;?php include("include/header/banner.php") ?&gt; &lt;?php include("include/header/nav.php") ?&gt; &lt;?php include("include/header/quicksearch.php") ?&gt; &lt;/div&gt; &lt;div id="content"&gt; &lt;div id="findoptions"&gt; &lt;select id="type" class="finddrops"&gt; &lt;option selected value="base"&gt;Please Select&lt;/option&gt; &lt;option value="DC Voltage"&gt;DC Voltage&lt;/option&gt; &lt;option value="DC Current"&gt;DC Current&lt;/option&gt; &lt;option value="AC Voltage"&gt;AC Voltage&lt;/option&gt; &lt;option value="AC Current"&gt;AC Current&lt;/option&gt; &lt;option value="Strainguage"&gt;Strainguage&lt;/option&gt; &lt;/select&gt; &lt;br&gt; &lt;select id="range" class="finddrops"&gt; &lt;option&gt;Please choose from above&lt;/option&gt; &lt;/select&gt; &lt;br&gt; &lt;select id="power" class="finddrops"&gt; &lt;option&gt;Please choose from above&lt;/option&gt; &lt;/select&gt; &lt;br&gt; &lt;select id="setpoint" class="finddrops"&gt; &lt;option&gt;Please choose from above&lt;/option&gt; &lt;/select&gt; &lt;br&gt; &lt;select id="output" class="finddrops"&gt; &lt;option&gt;Please choose from above&lt;/option&gt; &lt;/select&gt; &lt;br&gt; &lt;select id="blarg" class="finddrops"&gt; &lt;option&gt;Please choose from above&lt;/option&gt; &lt;/select&gt; &lt;/div&gt; &lt;div id="findresults" class="finddrops"&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="footer"&gt; &lt;?php include("include/footer/footer.php") ?&gt; &lt;/div&gt; </code></pre> <p>And this is my PHP running on the backend:</p> <pre><code>&lt;?php //\\ MODULAR DEPENDANT DROPDOWNS \\// //creates DB connection $dbHost = 'host'; $dbUser = 'user'; $dbPass = 'pass'; $dbDatabase = 'database'; $con = mysql_connect($dbHost, $dbUser, $dbPass) or trigger_error("Failed to connect to MySQL Server. Error: " . mysql_error()); mysql_select_db($dbDatabase) or trigger_error("Failed to connect to database {$dbDatabase}. Error: " . mysql_error()); //prevents injections //any order $type = mysql_real_escape_string(urldecode($_GET['type'])); isset($_GET['range'])?$range = mysql_real_escape_string(urldecode($_GET['range'])):""; isset($_GET['power'])?$power = mysql_real_escape_string(urldecode($_GET['power'])):""; isset($_GET['setpoint'])?$setpoint = mysql_real_escape_string(urldecode($_GET['setpoint'])):""; //forms the query depending on what data is recieved through GET //first option on the bottom; last option on the top to avoid conflicts if (isset($_GET['setpoint'])) { $query = "SELECT DISTINCT stp FROM meters WHERE sio='$range' AND pso='$power' AND stp='$setpoint' ORDER BY model"; } elseif (isset($_GET['power'])) { $query = "SELECT DISTINCT stp FROM meters WHERE sio='$range' AND pso='$power' ORDER BY model"; } elseif (isset($_GET['range'])) { $query = "SELECT DISTINCT pso FROM meters WHERE sio='$range' ORDER BY model"; } else { $query = "SELECT DISTINCT sio FROM meters WHERE sit LIKE '%$type%' ORDER BY model"; } //creates a result array from query results $result = mysql_query($query); //outputs dropdown options dependent on what GET variables are set //first option on the bottom; last option on the top to avoid conflicts if (isset($_GET['setpoint'])) { while ($row = mysql_fetch_array($result)) { echo "&lt;option value='" . $row{'stp'} . "'&gt;" . $row{'stp'} . "&lt;/option&gt;"; } } elseif (isset($_GET['power'])) { echo "&lt;option&gt;Choose Setpoint Options&lt;/option&gt;"; while ($row = mysql_fetch_array($result)) { $row{'stp'} = ucfirst($row{'stp'}); //capitalizes the first letter; necessary? echo "&lt;option value='" . $row{'stp'} . "'&gt;" . $row{'stp'} . "&lt;/option&gt;"; } } elseif (isset($_GET['range'])) { while ($row = mysql_fetch_array($result)) { echo "&lt;option value='" . $row{'pso'} . "'&gt;" . $row{'pso'} . "&lt;/option&gt;"; } } else { while ($row = mysql_fetch_array($result)) { echo "&lt;option value='" . $row{'sio'} . "'&gt;" . $row{'sio'} . "&lt;/option&gt;"; } } //Thanks to Chris Coyier for the wonderful examples on CSS-Tricks //A Web Application by Zach Klemp ?&gt; </code></pre> <p>Again, you can view the script <a href="http://new.foxmeter.com/find.php" rel="nofollow" title="find.php">here</a>.</p> <p>Thanks for any and all help getting this to work! It doesn't seem like this should be too hard I'm just not sure at how I should be telling the script to keep everything in the right encoding.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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