我想通过文本框值传递Mysql查询

时间:2019-10-30 07:05:36

标签: php jquery html ajax

$query="SELECT * FROM table1 where name='Vidya'";

我的文本字段是

<input type='hidden' value='<?php echo $query;?>' id='getsearchquery' name='getsearchquery'>

当我尝试提醒输入字段值时,我得到

SELECT * FROM table1 where name=

2 个答案:

答案 0 :(得分:1)

您必须转义引号

"<input type='hidden' value=\"<?php echo $query;?>\" id='getsearchquery' name='getsearchquery'>"

//You can assign the input field to a variable as below

$field="<input type='hidden' value=\"$query\" id='getsearchquery' name='getsearchquery'>";

答案 1 :(得分:0)

<?php
$query="SELECT * FROM table1 where name='Vidya'";
?>
<input type='hidden' value="<?php echo $query;?>" id='getsearchquery' name='getsearchquery'>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript">
    alert($('#getsearchquery').val());
</script>

问题是Vidya单词包含在单引号中,而您输入的值也包含在单引号中。将其更改为双引号