0

I have done everything as was outlined on this site: https://phpdelusions.net/mysqli_examples/prepared_select

Here's my code:

$conn = new mysqli($servername, $username, $password, $dbname);

$sql = "SELECT east FROM postcodes WHERE postcode=?"; // SQL with parameters
$stmt = $conn->prepare($sql); 
$stmt->bind_param("s", $A);
$A = $_REQUEST['postcode'];
$stmt->execute();
$result = $stmt->get_result(); // get the mysqli result
$r1 = $result->fetch_assoc(); // fetch data  

echo implode ($r1);

If I don't use "implode" it gives me "Notice: Array to string conversion"

What do I do? How can I assign result to $r1 variable and then use it without implode?

Dharman
  • 30,962
  • 25
  • 85
  • 135
Blade
  • 1
  • 2
  • 2
    Have you tried using `print_r($r1);` to see what it contains? – Nigel Ren Nov 19 '20 at 19:27
  • 1
    Why do you think there's something wrong? Just use `echo $r1['east']` – Barmar Nov 19 '20 at 19:29
  • Does this help? [https://stackoverflow.com/questions/20017409/how-to-solve-php-error-notice-array-to-string-conversion-in](https://stackoverflow.com/questions/20017409/how-to-solve-php-error-notice-array-to-string-conversion-in) – Rob Moll Nov 19 '20 at 19:30
  • [`fetch_assoc()`](https://www.php.net/manual/en/mysqli-result.fetch-assoc.php) returns an associative array. Even if there is only 1 field selected. You have something like `[ 'east' => 'Some Value' ]` – Cid Nov 19 '20 at 19:31
  • 1
    `$r1` is an array. You can use it as an array. You cannot echo out arrays without manipulation such as implode. However you might want to look into https://www.php.net/manual/en/mysqli-stmt.bind-result.php if you want to assign the column value to a variable. – aynber Nov 19 '20 at 19:33
  • i up dated my first post, since it doesnt work in comments sectio Thanks for help guys – Blade Nov 19 '20 at 19:47
  • Please clarify what you want to happen. "Something wrong" is not a valuable question for Stack Overflow – Dharman Nov 19 '20 at 22:53

0 Answers0