开发者

Have app that gets input from User, and pushes to server, and PHP inserts into mySQL, but PHP isn't handleing it correctly is my assumption

I got my app to accept User input and according to LogCat the app goes through my HTTP Post. But my data isn't appearing on the database. so I'm thinking its a Issue of my PHP code, but I have no idea what I did wrong with it. I'm new to developing for android, and the research I came up with was possibly use a JSON object. I looked up a few examples of some and tried to get them to work, but kept coming up with errors. Any help would be greatly appreciated :) Here's my Code & PHP hope it can help :)

private class GrabURL extends AsyncTask<String, Void, Void> {
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();;
private ProgressDialog Dialog = new ProgressDialog(HTTPpostActivity.this);
protected void onPreExecute() {
Dialog.setMessage("Sending value..");
Dialog.show();
nameValuePairs.add(new BasicNameValuePair("fname","Donald"));
nameValuePairs.add(new BasicNameValuePair("lname", "Android"));
nameValuePairs.add(new BasicNameValuePair("phone", "502-409-5478"));
nameValuePairs.add(new BasicNameValuePair("partyNum", "10"));
nameValuePairs.add(new BasicNameValuePair("date", "2011-09-09"));
nameValuePairs.add(new BasicNameValuePair("time", "4:40"));
}

protected Void doInBackground(String... urls) {
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
httpclient.execute(httppost);
}catch(Exception e){
Log.e("log_tag", "Error in http connection "+e.toString());
}
return null;
}

PHP:

<?PHP   

$link = mysql_connect($host, $username, $password) or die("Connection ERROR");

$db = mysql_select_db("$db_name") or die ("CONNECTION ERROR");

$resTime = $_GET['time'];
$fname = $_GET['fname'];
$lname = $_GE开发者_如何学PythonT['lname'];
$phone = $_GET['phone'];
$date = $_GET['date'];
$partyNum = $_GET['partyNum'];



$query = "INSERT INTO RESERVATION (DATE, FNAME, LNAME, NUMBERINPARTY, RESOTIME, PHONENUMBER) VALUES ('" .$date. "', '" .$fname. "', '" .$lname. "', '" .$partyNum. "', '" .$resTime. "', '" .$phone. "');"; 
?>


The method you are trying to use is HttpPost. In your php file you are trying to use the GET method, trying using the post method like this:

<?PHP   

$link = mysql_connect($host, $username, $password) or die("Connection ERROR");

$db = mysql_select_db("$db_name") or die ("CONNECTION ERROR");

$resTime = $_POST['time'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$phone = $_POST['phone'];
$date = $_POST['date'];
$partyNum = $_POST['partyNum'];



$query = "INSERT INTO RESERVATION (DATE, FNAME, LNAME, NUMBERINPARTY, RESOTIME, PHONENUMBER) VALUES ('" .$date. "', '" .$fname. "', '" .$lname. "', '" .$partyNum. "', '" .$resTime. "', '" .$phone. "');"; 
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜