doulue1949 2013-05-01 03:47
浏览 36
已采纳

将变量从$ _GET传递到另一个页面

So, I have am trying to do a simple search bar. The query that is entered into the search is pulled to another page. That works perfectly fine. The problem occurs when I try to use that variable in a script that increments the query's row in the database table. Everything works fine when I just put the name of a table element in instead of the variable, but I need to grab what they searched for to be able to get it to work properly.

I think you can do this with a session, but I don't want to bother with sessions for such a small project.

This is how I pull the variable from the search bar:

$query = $_GET['query'];

That works fine, but I can't get it to a new page to use in this piece of code:

mysql_query("UPDATE inventory SET Sold=Sold+1 WHERE Brand='Skittles' OR Type='Candy'");
  • 写回答

3条回答 默认 最新

  • dsjswclzh40259075 2013-05-01 04:16
    关注

    Sessions are fairly easy to work with.

    <?php 
    
        session_start();
    
        $_SESSION['query'] = $_GET['query'];
    
    ?>
    

    That would store it, then to retrieve it use it just like you would $_GET['query'] but use $_SESSION['query']. It'll persist until the session expires or is destroyed.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写