But after returning the value of the read file to arduino, it always gets 0. I think, somehow, the arduino misinterpret the data. I also thought it might be the data type that I am using for linequery. Any suggestions/idea/solution? Please help. thanks!

ticket = char(Serial.read()); successtxt = "Order successful! Your ticket order is: ";You are going to run out of ticket numbers after you sell 10 tickets, if the first one is 0.

You are pissing memory away right and left. On a platform with 2048 bytes of memory, that is really not a good idea. Get rid of EVERY instance of the String class, and learn to do it like a big boy - using the char arrays without crutches.

I have a php code which will log 0, 1, 2, or 3 to a text file (Query.txt). After execution, the value is successfully logged on the txt file. I have then an arduino code which prints #S|QUERY|[1]# to command gobetwino to read query.txt. it is successfully read and then returns a value to arduino using variable linequery. I have then a serial.println(linequery) and it prints a value of 0 instead of the right value. More confusing is that the command output window in gobetwino prints the right value. What do you think is the problem? Can someone help me? thanks!

You need to keep reading from the serial port until you have received the complete response. Typically that would be a line of text terminated by a carriage return and/or new line character. So you can simply keep reading until you receive one of those. The code could look something like this:

Peter, I already got it by using while loop until he gets the last byte whenever serial is available. but here's another problem. the serial.read() seems to read the previous logs on the serial. that's why when the serial is initially null, the first process returns null. the second process returns the output for the first process. and consecutively for the next processes. can u help me out?