Please i am trying to send from an EditText a text with space between words but nothing inserted in my db !
and when i send a text with no space works and inserted !
please what is the problem here ??
MyAsyncTaskresources attemptLogin= new MyAsyncTaskresources();
attemptLogin.execute("http://xxx.xxxxx.com/add_demande.php?de="+infos_demande.getStringExtra("de").toString()+"&a="+infos_demande.getStringExtra("a").toString()+"&date="+infos_demande.getStringExtra("date").toString()+"&heur="+infos_demande.getStringExtra("heur").toString()+"&id_user="+infos_demande.getStringExtra("id_conducteur"+i).toString());
Have you try adding
N'
as a first part of the string?
You need to Encode the String values using URLEncoder.encode(<Query Value>,"UTF-8") before appending the values to the URL String.
MyAsyncTaskresources attemptLogin= new MyAsyncTaskresources();
attemptLogin.execute("http://xxx.xxxxx.com/add_demande.php?de="+URLEncoder.encode(infos_demande.getStringExtra("de").toString(),"UTF-8")+"&a="+URLENcoder.encode(infos_demande.getStringExtra("a").toString(),"UTF-8")+"&date="+URLEncoder.encode(infos_demande.getStringExtra("date").toString(),"UTF-8")+"&heur="+URLEncoder.encode(infos_demande.getStringExtra("heur").toString(),"UTF-8")+"&id_user="+URLEncoder.encode(infos_demande.getStringExtra("id_conducteur"+i).toString(),"UTF-8"));
First make your code readable, build your string before putting it in attemptLogin.execute(...)
now you have your string build you can check your string, try that and make sure your attemptLogin.execute() argument is a legit string!
using volley is best and fast than use this old process
volley library in android , can send request and get response easy and adding parameter such as string and no problem of space , and there is handle for server error to check where your error
Related
While I was trying the following SQL command , I got sql error.
INSERT INTO exampleTbl VALUES('he doesn't work for me')
where doesn't contain the apostrophe.
What is the way to insert text having ' (apostrophe) into a SQL table.
In SQL, the way to do this is to double the apostrophe:
'he doesn''t work for me'
However, if you are doing this programmatically, you should use an API that accepts parameters and escapes them for you automatically. Programmatically escaping and using string concatenation to assemble a query yourself is a sure way to end up with SQL injection vulnerabilities.
INSERT INTO exampleTbl VALUES('he doesn''t work for me')
If you're adding a record through ASP.NET, you can use the SqlParameter object to pass in values so you don't have to worry about the apostrophe's that users enter in.
$value = "he doesn't work for me";
$new_value = str_replace("'", "''", "$value"); // it looks like " ' " , " ' ' "
INSERT INTO exampleTbl (`column`) VALUES('$new_value')
try this
INSERT INTO exampleTbl VALUES('he doesn''t work for me')
insert into table1 values("sunil''s book",123,99382932938);
use double apostrophe inside of single apostrophe,
it will work
I know the question is aimed at the direct escaping of the apostrophe character but I assume that usually this is going to be triggered by some sort of program providing the input.
What I have done universally in the scripts and programs I have worked with is to substitute it with a ` character when processing the formatting of the text being input.
Now I know that in some cases, the backtick character may in fact be part of what you might be trying to save (such as on a forum like this) but if you're simply saving text input from users it's a possible solution.
Going into the SQL database
$newval=~s/\'/`/g;
Then, when coming back out for display, filtered again like this:
$showval=~s/`/\'/g;
This example was when PERL/CGI is being used but it can apply to PHP and other bases as well. I have found it works well because I think it helps prevent possible injection attempts, because all ' are removed prior to attempting an insertion of a record.
yes, sql server doesn't allow to insert single quote in table field due to the sql injection attack. so we must replace single appostrophe by double while saving.
(he doesn't work for me) must be => (he doesn''t work for me)
you can use backslash '\' if you want to display a single quote in your text.
INSERT INTO exampleTbl VALUES('He doesn(\')t') ;
I am creating a calculator app in android. It should calculate anonymously whatever is on textBox. For e.g. I enter 1+2.5-5*8 in textBox. But when I call addition method the app gets crashed. Because the input is in string format and answer I want is in numeric format. I used string buffer. I tried in java that when I enter (1+1+3-1) in stringBuffer and I display using println() method it give correct answer but same does not happen with string buffer when I take that value from editText.
You have to convert string into integer or float.
Use Integer.parseInt("") method to covert to integer and Float.parseFloat("") to convert to float.
First of all welcome to StackOverFlow
It might help if you add code and the error log in the question
So I am gonna cover all the possible things that might be happening wrong in your program:
NumberFormatException- you might not be converting the string "12" into int 12 to do so use Interger.parseInt(your string buffer with number only here);
Try using a stack and a queue for your solution (google it you will get details)
You might be making a mistake in getting string from edittext it sometimes give NullPointerException
if above is not enough comment and add your code asap
I am hitting a particular URL and getting some response from it. I am storing the response into a string. But my string stores about 3500 characters and then shows ... . How can I make it to store all the response data into the String? Please note that response is a JSON.
Since you are dealing with a large json, better use JsonReader . This way you wont have to worry about those dots, and the outofmemory exceptions.
Try to debug and have a proof by displaying your String.length() value... Is it really 3500 ?
I've got an Android app that consumes a REST webservice that can return a large amount of data as a JSON string. The data is then displayed in its raw form in a TextView.
The app works fine when its a small amount of data, but for a large amount of data I get an error in LogCat that says "Cannot get TextLayoutCache value".
I know that it has to be something to do with space in the TextView but I'm wondering if anyone has any further knowledge so I can figure out the best way to get around this.
This can be fixed by specifying a maxLength for the TextView, e.g.:
android:maxLength="9000"
I had this issue when trying to output a very large (~64K long) text string to WebView alert box.
All I want to do is to send a URL String into my RESTFUL web service with some kind of code like this
URL someURL= new URL("http://myWebService:port/service/"+CharSequence.getText());
Its all going well until I found error with space character in my URL. I found some solution about replacing the space character with %20 which is I already defined with something like this :
URL someURL= new URL("http://myWebService:port/service/"+CharSequence.getText().replace(" ", "%20"));
Everything, again, seems going well until i found that the replace(Char oldChara, Char newChara) function can only replace ONE space character, and not two.
For brief example when I send the CharSequence.getText() with values "We won" there will be no error, but when I change the values into "We won the battles" there will be an error issuing that there are some illegal character sent to my RESTFUL web service.
Any kind of answer will come up with my great thanks and big salute
~Regards~
Use replaceAll instead of replace.
Although, you should really be doing proper URL encoding. You can use URLEncoder.encode
for example.