AJAX showing retrieved values as undefined

前端 未结 5 1826
暗喜
暗喜 2021-01-21 00:17

I am using AJAX to send values to PHP and retrieve the values from PHP. The problem is the value i am getting from PHP is viewed as undefined in AJAX. Please help me solve this

5条回答
  •  南旧
    南旧 (楼主)
    2021-01-21 00:23

    Just a point no-one else has covered yet: you need to use double quotes or concatenation here:

    'select * from $channel'; // no
    "select * from $channel"; // yes
    'select * from '.$channel; // yes
    

    Variables won't be resolved inside single quotes so you are trying to select from a table that is literally called $channel.

    Also please use some kind of validation on $channel as what you have is very vulnerable to SQL injection attack.

提交回复
热议问题