Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9248923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:04:02+00:00 2026-06-18T10:04:02+00:00

I have been slaving over this code for nearly 16 hours and the result

  • 0

I have been slaving over this code for nearly 16 hours and the result still makes no sense to me at all.

What I am doing is making a Java Program that sends a POST parameter to a URL. I am also testing the same method using a form with Firefox.

The trouble is, on Firefox, I test the value that is being sent and echo it out. I also test the value against a value I know it should equal, but when Java sends the value, it returns false, but Firefox returns true, why is this?

PHP Code:

    $player = array('code' => "code");
    $msg = "neither";

    if(isset($_POST['player']))
    {
        $player = getPlayer(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME, DB_TABLE_NAME, $_POST['player']);
        $msg = "?player=" . $_POST['player'] . " post";
    }

    function getPlayer($DbHost, $DbUsername, $DbPassword, $DbName, $DbTableName, $name)
    {
        try
        {
            $dsn = "mysql:host=$DbHost;dbname=$DbName"; //Data Source Name = MySQL
            $dbc = new PDO($dsn, $DbUsername, $DbPassword); //Connect to DB

            $query = "SELECT * FROM $DbTableName WHERE name = :name";
            $result = $dbc->prepare($query); //Prepare query

            if($name == "pathurs")
            {
                echo 'true:' . $name;
            }
            else
            {
                echo 'false:' . $name;
            }

            $result->bindParam(':name', $name, PDO::PARAM_STR);

            $result->execute(); //Execute Query

            while($row = $result->fetchObject()) //Loop through results
            {
                $array = array();

                //Convert stdClass($row) to array($array)
                foreach($row as $key => $value)
                {
                    $array[$key] = $value;
                }

                $dbc = null;
                return $array;
            }
        }
        catch(PDOException $e)
        {
            echo $e->getMessage();
        }
    }

    echo "code:" . $player['code'] . $msg . $_POST['player'];

Java Code:

public String getContent(String url, String params)
    {
        String result = "";

        try
        {
            this.url = new URL(url);
            try
            {
                URLConnection con = this.url.openConnection();
                con.setDoOutput(true);

                PrintStream ps = new PrintStream(con.getOutputStream());
                ps.println(params);

                InputStream is = con.getInputStream();
                BufferedReader in = new BufferedReader(new InputStreamReader(is));
                String line = "";

                while((line = in.readLine()) != null)
                {
                    result += line;
                }

                System.out.println(result);
            }
            catch(IOException e)
            {
                e.printStackTrace();
            }
        }
        catch(MalformedURLException e)
        {
            e.printStackTrace();
        }

        return result;
    }

Firefox Output:

true:pathurscode:code?player=pathurs postpathurs

Java Program Output:

false:pathurscode:?player=pathurs postpathurs

Why is it when I compare $name == "pathurs" (In PHP Code on line 20) it comes up true in Firefox but false in Java? It doesn’t make sense to me seeing they’re both tested in the PHP page and they are both strings, and they both output in the echo that they both equal a form of 'pathurs'

Is there something I’ve done wrong? I can’t currently fathom a reason it would only happen when Java sends the information and not when Firefox does. I tested by replaced the PDO query with:

$query = "SELECT * FROM $DbTableName WHERE name = 'pathurs'";

and it works perfectly on both outputs. This makes me EVEN more confused. I hope someone can help!

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:04:03+00:00Added an answer on June 18, 2026 at 10:04 am

    It’s because you are using:

    ps.println(params);
    

    So it’s sending a new line character after the params, ie: player=pathurs\n

    Try:

    ps.print(params);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been slaving over this for hours now. I need a lightbox to
I have been going over this for hours and cannot find the problem. I
Have been working on this question for a couple hours and have come close
Ok, I've been digging around and haven't found an answer to this. I have
This seems to be a bit of an infamous error all over the web.
I have been through pretty much every post on this site it seems that
I have been working over an year with Magento and have learned it good
I have been trying to make this work for a long time now. In
I've been beating myself over the head with this app migration for a few
So I have been working on this ppt add-in. I have been saving strings

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.