-3

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

R2D2
  • 131
  • 1
  • 2
  • 10

1 Answers1

2

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?

Community
  • 1
  • 1
Hanky Panky
  • 46,730
  • 8
  • 72
  • 95