This question is about how best to encode, send and store information between JavaScript, PHP, and MySQL
I am doing a GET request from HTML/JavaScript to my PHP server, which is then storing the data in mySQL. My solution in the one case I've been using it in, and I think it should work in all cases (If it won't, please let me know?)
I got tripped up for a bit by difference between php and javascript uri/urlencoding. JavaScript encodes spaces as "%20"s, but php encodes spaces with "+". So now what I am doing is converting all spaces to pluses before I uriEncode in JavaScript
JavaScript:
docTitleInput.value = encodeURI(document.title.replace(/\s/g,"+"));
PHP: In PHP I am directly storing the encoded value in MySQL
For instance, the string: '"Problems" in myApp' is stored in MySQL as
%22Problems%22+in+myApp
I thought this might be better than storing the decoded string, as quotes and other special characters can make db querying more difficult, in my experience. On the other hand, it makes data in the db harder to read... Am I wrong in this thinking?
Somewhere else I am looking up the hash (in another column) by sending this encoded string to PHP and use PHP to query the DB with exactly what's sent from JavaScript.
$stmt = $pdo->prepare("select hash from b where c=? and d=?");
And executed where d is %22Problems%22+in+myApp
Is this the best way to do what I am doing? Am I going to come to regret storing document titles in their encoded form?
Anyone with experience in these kinds of things, I'd appreciate your insights