i try to use thread in my code,, and it was successfull..
so i tried this code
public void commandAction(Command c, Item item) {
// TODO Auto-generated method stub
if(item == login){
new Thread (this).start();
}
public void run() {
String hasil = null;
String userName = username.getString();
String passWord = password.getString();
try {
hasil = new String(connect.load(userName,passWord));
Alert alarm = new Alert("LOGIN");
alarm.setTimeout(Alert.FOREVER);
alarm.setString(hasil);
display.setCurrent(alarm);
} catch (IOException ex) {
Alert alarm = new Alert("LOGIN");
alarm.setTimeout(Alert.FOREVER);
alarm.setString(hasil);
display.setCurrent(alarm);
}
}
it was successfull,,but then, after i login,,i want it to redirect into other class,, whenever i add "if else" after
hasil = new String(connect.load(userName,passWord));
they redirect but didnt detect wrong or not,, even i put wrong id and pw,, they still running to my other class which they shouldnt go,,
this is my ConnectServer code..
private String url;
private Form form;
public ConnectServer(String url){
this.url = url;
}
public byte[] load(String user, String pass) throws IOException{
byte[] byteBuffer = null;
HttpConnection hc = (HttpConnection) Connector.open(this.url);
try {
hc.setRequestMethod(HttpConnection.POST);
hc.setRequestProperty("User-Agent",
"Profile/MIDP-1.0 Confirguration/CLDC-1.0");
hc.setRequestProperty("Accept_Language", "en-US");
//Content-Type is must to pass parameters in POST Request
hc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
OutputStream os = hc.openOutputStream();
String userName = "username=" + user;
String passWord = "&password=" + pass;
os.write(userName.getBytes());
os.write(passWord.getBytes());
if (hc.getResponseCode() == HttpConnection.HTTP_OK) {
InputStream is = hc.openInputStream();
try {
int len = (int) hc.getLength();
if (len > 0) {
byteBuffer = new byte[len];
DataInputStream dis = new DataInputStream(is);
dis.readFully(byteBuffer);
} else {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buffer = new byte[512];
int count;
while ((count = is.read(buffer)) >= 0) {
bos.write(buffer, 0, count);
}
byteBuffer = bos.toByteArray();
}
} finally {
is.close();
}
}
} finally {
hc.close();
}
return byteBuffer;
}
and this is my php code
<?php
$user = "root";
$pass = "1234";
$host = "localhost";
$db = "lms";
$conn = mysql_connect($host,$user,$pass);
mysql_select_db($db);
if(!$conn){echo"Gagal Koneksi ke Database";}
$flag = false;
if($_POST['username'] != "" and $_POST['password'] != "")
{
$username = $_POST['username'];
$password = $_POST['password'];
$flag = true;
}
else
{
echo"username dan password harus diisi";
}
if($flag == true)
{
$sql = "SELECT * FROM employee WHERE emp_other_id = '".$username."' AND emp_password = '".$password."'";
$hasil = mysql_query($sql);
$jmlacc = mysql_fetch_array($hasil);
if($jmlacc > 0)
{
echo"valid";
}else{
echo"invalid";
}
}
?>