1

I've used the answer given here (how do i insert a variable? from a form into a file_get_contents link) however, It is still not working for me.

But this is not working, I do not know why?

1
  • $code = $_POST['search']; need to be before the file_get_contents() don't you think? Commented Apr 20, 2015 at 19:29

1 Answer 1

1

You need to place/assign your POST array and variable first, not after:
(Kind of like putting the horse after the wagon, as it were).

<?php
$code = $_POST['search'];
$json = file_get_contents("http://myurl.com/user=". $code);
$obj = json_decode($json);
?>

Because as it stands, you'd be getting an "Undefined index/variable..." notice, had you been checking for errors.

Add error reporting to the top of your file(s) which will help find errors.

<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);

// rest of your code

Sidenote: Error reporting should only be done in staging, and never production.

Sign up to request clarification or add additional context in comments.

1 Comment

@Jay You're welcome Jay. Plus, I didn't see AbraCadaver's comment; I was preparing my answer at the same time it was written. Just for the record ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.