3

I'm trying to send input from an edittext to PHP. If I send in something with no spaces it works ok, but crashes with spaces and says this:

illegal character

...which refers to the space.

Obviously it's a matter of getting the quotes correct but for some reason I just can't get this right.

Where do I add the quotes?

Is it in Java during creating the URL?

http://example.com/android/project_group_notes_details.php?course=\'"+sessionCourse+"\'";

or while creating the Variable?

String sessionCouse = "\'Software Development With Spaces\'";

or is it somehow done server side?

AStopher
  • 4,207
  • 11
  • 50
  • 75
user3216557
  • 81
  • 2
  • 4
  • 9

2 Answers2

5

A standard browser takes any spaces entered into the address bar and replaces them with %20; HTML's space character.

HTTP does not do this, the browser does, meaning that you have two options:

  1. Create a function to take in a string and replace all spaces with %20;
  2. Manually replace spaces with %20

For example:

String sessionCouse = "\'Software Development With Spaces\'";

should actually be

String sessionCouse = "\'Software%20Development%20With%20Spaces\'";
AStopher
  • 4,207
  • 11
  • 50
  • 75
0

When communicating with a backend server programmatically you should use URL encode to encode you input properly:

String fullURL = "http://example.com/android/project_group_notes_details.php?course=\'"+ URLEncoder.encode(sessionCouse, "UTF-8") + "\'";
RonnyRoos
  • 21
  • 1
  • Seems to produce " course='Software+Systems+Development' " Which returns no results even though there is a "Software Systems Development" result in the database. – user3216557 Mar 17 '15 at 18:12
  • The purpose of the URLEncoder is to do just that, encode strings to valid URL:s. Have a look here for more info: http://stackoverflow.com/questions/10786042/java-url-encoding-of-query-string-parameters – RonnyRoos Mar 18 '15 at 11:08