Any advice would much appreciate.
Try to ask this question again, and be more specific.
Clean your code, indent it and apply comments for better understanding..
In the first look, in your "if else" case where the $string is not 'sgdsgdsgsgd'
you list all the members, but you query down only the name field.
In you rest code you're trying to access the "mydata" field (you have not selected before!!).
For the test you should use "select * from members" sql query instead.
If you redirect a page in server side , the previously displayed contents may cause an error message! "header already sent..."