简体   繁体   中英

Ajax fetch variable to php to select from SQL

So I need to pass variable to my "fetch" php, on fetch.php I make query to mysql DB with given parameters.

And now I am stuck..

I am able to fetch variable like so :

data: {
    "Kood":'<?php echo $params->get('Kood');?>'
},

Then I catch it in fetch.php and make request to db :

(after some if statements I make sql request)

$query .= 'and kood LIKE "%'.$_POST["Kood"]["value"].'%"  ';

Everything works almost fine but instead of "Like" I would use Equal, if I change my request to equal then it fails to get any results back..

Example :

select * 
from table 
where kood='KERR2018' 

(btw when I use like then it also gets KERR2019 results somehow..)

and thats how I tried to get "equal" to :

$query .= 'and kood ="'.$_POST["Kood"]["value"].'"  ';

I feel like, it looses numbers and uses only chars?

When I made var in fetch.php ( $Kood="KERR2018"; ) then it worked as I wanted..

$query .= 'and kood ="'.$_POST["Kood"]["value"].'"  ';

was wrong aproach. should be without "value"

$query .= 'and kood ="'.$_POST["Kood"].'"  ';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM