package hello;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.io.*;
import javax.microedition.io.*;
import java.util.*;
import java.lang.*;
public class HelloMIDlet extends MIDlet implements CommandListener
{
Display display;
Command exit;
Command login;
Form screen;
public TextField location;
TextField outputfield;
InputStream in = null;
String url = new String();
public HelloMIDlet()
{
display = Display.getDisplay(this);
exit = new Command("Exit",Command.EXIT, 1);
login = new Command("Insert", Command.SCREEN,2);
location = new TextField("Enter the location:", "", 10, TextField.ANY);
outputfield= new TextField("Status:", "", 256, TextField.UNEDITABLE);
screen = new Form("Login Form In Project");
screen.append(location);
screen.append(outputfield);
screen.addCommand(exit);
screen.addCommand(login);
screen.setCommandListener(this);
}
public void startApp()
{
display.setCurrent(screen);
}
public void pauseApp()
{
}
public void destroyApp(boolean unconditional)
{
}
public void update_action()
{
// Create a thread to actually connect to the webserver
Thread t = new Thread()
{
public void run()
{
//open connecttion
try
{
outputfield.setString("Attempting to Connect...");
url = generateGetUrl("http://localhost/dirty/location.php",location.getString());
System.out.print("\n" + url + "\n");
if(updateSite(url)==1)
outputfield.setString("Sucessfully Logined in website...");
else
outputfield.setString("Failed to sign in. =(");
}
catch(IOException e)
{
outputfield.setString("Failed to Connect. =(");
}
}
};
t.start();
}
public void commandAction(Command c, Displayable s)
{
if(c == login)
{
update_action();
}
if(c == exit)
{
destroyApp(false);
notifyDestroyed();
}
}
public String generateGetUrl(String url, String text)
{
String newUrl = new String();
StringBuffer c = new StringBuffer(text);
for(int i=0; i<c.length(); i++)
{
if(c.charAt(i)==' ')
{
c = c.insert(i,"%20");
c = c.deleteCharAt(i+3);
}
}
newUrl = url + "?text=" + c.toString();
return newUrl.toString();
}
public int updateSite(String url) throws IOException
{
HttpConnection conn = null;
DataOutputStream out = null;
try
{
conn = (HttpConnection)Connector.open(url);
conn.setRequestMethod(HttpConnection.GET);
conn.setRequestProperty("Connection", "close");
if(conn.getResponseCode() == HttpConnection.HTTP_OK)
{
return 1;
}
else
{
return 0;
}
}
catch(IOException e)
{
System.out.print("Error Connection to website.\n");
return 0;
}
}
}
and thats my php code
<?php
$dbservertype='mysql';
$servername='localhost';
$dbusername='root';
$dbpassword='';
$dbname='bts';
connecttodb($servername,$dbname,$dbusername,$dbpassword);
function connecttodb($servername,$dbname,$dbuser,$dbpassword)
{
global $link;
$link=mysql_connect ("$servername","$dbuser","$dbpassword");
if(!$link){die("Could not connect to MySQL");}
mysql_select_db("bts",$link) or die ("could not open db".mysql_error());
mysql_select_db('bts');
$loc = location
mysql_query("insert into sheet1 (Location) values ('islam')");
mysql_close($con);
}
?>
and when i run my php from browser i get this error
Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\dirty\location.php on line 25

New Topic/Question
Reply




MultiQuote





|