<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
SAMPLE QUERY: "UPDATE user SET fname = '".$fname."', lname = '".$lname."' WHERE id = '".$id."'"
class SQLI_TO_PDO {
constructor (parentElement){
this.parentElement = parentElement;
this.ui;
this.build();
}
build(){
this.ui = $(`<div class="sqli-to-pdo"><textarea class="query-input" placeholder="Enter Your PHP Query Code Here..."></textarea><button class="convert-button">Convert</button><div class="query-output"></div>`);
this.parentElement.append(this.ui);
let input = this.ui.find('textarea.query-input');
this.ui.find('button.convert-button').click(function(){
let v = input.val();
let bits = v.split('.');
// all in peices - determine how it should be put back together
/*
start by checking for false positives where the . is used in
stricter lookups of aliases
if both the last character of previous bit and first
character of this bit are a value and it is not a $
*/
let constructed_string = '';
let constructed_array = [];
for(let i=0;i<bits.length;i++){
if(i>0){
if(
(bits[i].substr(0,1) == '$') ||
(bits[i].substr(0,2) == ' $') ||
(bits[i].substr(0,3) == ' $') ||
(bits[i].substr(0,24) == 'mysql_real_escape_string') ||
(bits[i].substr(0,25) == ' mysql_real_escape_string')
){
constructed_string += '?';
constructed_array.push(bits[i].trim());
} else {
// clean up the wrappers
bits[i] = bits[i].replaceAll("'",'');
bits[i] = bits[i].replaceAll('"','');
bits[i] = bits[i].replaceAll(' ',' ');
bits[i] = bits[i].replaceAll(' ',' ');
console.log("bits[i]: " + bits[i]);
constructed_string += bits[i];
}
} else {
if(bits[i].substr(0,1) == '"'){
bits[i] = bits[i].substr(1);
}
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.