dongya6381 2015-05-20 06:46
浏览 20
已采纳

mysqli_fetch_row()没有按预期工作

Am I using mysqli_fetch_row() the right way ?? I know the customer name and I wanna find out the Env_lines value in that same record. There is only one record with that customer name. I'm not getting an output when i do echo $env_lines. What might be the problem?

<?php require_once("config.php") ?>
<?php require_once("functions.php") ?>

test

<?php

    $customer = 'Bickery';
    echo ' <br> 1)'.$customer;

    $sql_customer = "SELECT * FROM `Customer` WHERE Cust_Name = '$customer' LIMIT 0,1";
    echo ' <br> 2)'.$sql_customer,'<br>';

    $customer_selection = mysqli_query($conn,$sql_customer);
    var_dump($customer_selection);
    $customer_row = mysqli_fetch_row($conn, $customer_selection);

    $env_lines = $customer_row["Env_Lines"];
    echo ' <br> 3)'.$env_lines;
?>

https://gist.github.com/anonymous/520319ac72e7f08419c4

This is the output

  • 写回答

1条回答 默认 最新

  • doudi4014 2015-05-20 06:52
    关注

    Manual Says

    mixed mysqli_fetch_row ( mysqli_result $result )

    Does that show anywhere that you need to give it your connection reference? No

    Remove your first parameter from here

    $customer_row = mysqli_fetch_row($conn, $customer_selection);
                                     ^
    

    Then

    Fetches one row of data from the result set and returns it as an enumerated array, where each column is stored in an array offset starting from 0 (zero). Each subsequent call to this function will return the next row within the result set, or NULL if there are no more rows

    That means this is not the right function to fetch an associative array, mysqli_fetch_assoc is (amongst others).

    $customer_row = mysqli_fetch_assoc($customer_selection);
    

    And oh, PHP guys on SO think this is our duty; here it goes

    How can I prevent SQL injection in PHP?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

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