weixin_33694620 2016-01-14 12:55 采纳率: 0%
浏览 61

PHP AJAX和MySQL

I tried to follow this tutorial http://www.w3schools.com/php/php_ajax_database.asp
I want to send the value from a select(with onchange) to change the sql query.

function myfunctionTime(time) {
      if (time=="") {
        document.getElementById("txtHint").innerHTML="";
        return;
      } 
      if (window.XMLHttpRequest) {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
      } else { // code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4 && xmlhttp.status==200) {
          document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
        }
      }
      xmlhttp.open("GET","book.php?id=<?php echo $FILM_ID; ?>&q="+time,true);
      xmlhttp.send();
    }

Here is the select with the onchange:

<p for="session">Time:</p>
<select class="form-control" id="session" name="session"onchange="myfunctionTime(this.value)"> 
    <option selected="selected" value="12:00">12:00</option>
    <option value="16:00">16:00</option>
    <option value="20:00">20:00</option>
</select>

Here is the PHP where I want to get the variable.

// Print all the get variables
    print_r($_GET);

    // Film session or time
    $session = "12:00"; 
    $session = $_GET['q'];
    echo "Session: ".$session;

    $query = "SELECT * FROM booking WHERE (FILM_ID = '$film_id' AND BOOKING_SESSION = '$session')";

And this is the error I get:

Notice: Undefined index: q in C:\xampp\htdocs...\book.php on line 271

  • 写回答

2条回答 默认 最新

  • weixin_33726313 2016-01-14 13:04
    关注

    Change your $session value to this

     $session = $_GET['id'];
    
    评论

报告相同问题?

悬赏问题

  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来