I try to show you the right direction:
First
Think about what you want do in mysql. Google for mysql injection. If you take mysql querys from client (browser) to your server, everyone could change it to something like drop database and believe me - you don't want have someone drop your database ;)
Second
Look at this PHP Database access. It's done with PDO. PDO is a PHP class that prevents mysql injections and will help you in many other cases later too.
<?php
$id = $_GET['id'];
$ownerName = $_GET['ownerName'];
$db = new PDO('mysql:host=localhost;dbname=<SOMEDB>', '<USERNAME>', 'PASSWORD');
$query = $db->prepare('SELECT * FROM `cards` WHERE `id` = :ID AND `owner` = :OWNER');
$query->execute(array(
':ID' => $id,
':OWNER' => $owner
));
$result = $query->fetchAll(); //$result is now an array of search result objects
You see, that you just send values via javascript to your php script. Of course, you could have several query strings in your php script and maybe get one with the combination of a special query ID and a switch? Up to you.
Example:
<?php
$queryNum = (int)$_GET['queryNum'];
$value1 = $_GET['val1'];
$value2 = $_GET['val2'];
switch($queryNum){
case 1:
$query = 'SELECT * FROM `cards` WHERE `id` = :ID AND `owner` = :OWNER';
$queryVals = array(':ID' => $value1, ':OWNER' => $value2);
break;
case 2:
$query = 'SELECT * FROM `cards` WHERE `color` = :COLOR AND `size` = :SIZE';
$queryVals = array(':COLOR' => $value1, ':SIZE' => $value2);
break;
default:
$query = 'SELECT * FROM `cards`';
$queryVals = array();
break;
};
$db = new PDO('mysql:host=localhost;dbname=<SOMEDB>', '<USERNAME>', 'PASSWORD');
$query = $db->prepare($query);
$query->execute($queryVals);
$result = $query->fetchAll(); //$result is now an array of search result objects
Third
Send only the values for your database query from javascript or HTML form to your php script.
Summary
That is really basic knowledge and my script examples are only simple examples that can show you the right direction. And never forgett to prevent the possibility that a user can change in any way your database query or php code!
I try and insert the end of the sql using this method nothing worksmeans