douyuben9434 2013-11-09 15:05
浏览 12

$ _SESSION存储错误的值

I made a portal where i have to fetch result with primary key as id i am using it everywhere storing it in a variable however there is a certain problem that i am facing

$sql="SELECT users from hostelusers WHERE users Like'%$roll%'"; 
$result = mysql_query($sql) or die(mysql_error());
        $rows=mysql_fetch_row($result);
        $uid=$rows[0];
$_SESSION['uid']=$uid;

In my code the variable $uid is echoing out values of column 1 ie users however I have selected column 0 which is id(in the table in mysql)

can't think of any mistake there

  • 写回答

1条回答 默认 最新

  • download12749 2013-11-09 15:21
    关注

    your mysql query string is wrong . You are using :

    $sql="SELECT users from hostelusers WHERE users Like'%$roll%'";
    

    And how do you expect to get id field in the result ??

    Moreover you will be having only a single column [field] in your rows[] and that is rows[0]

    if you want to use rows[0] to get your id field

    Change your query to this

    $sql="SELECT id from hostelusers WHERE users Like'%$roll%'";
    

    or this:

    $sql="SELECT * from hostelusers WHERE users Like'%$roll%'";
    

    and it will work for sure

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度