[英]How to Update and Insert database at same time using php in eclipse
以下是我的日食零件代碼和php文件。 單擊不同意按鈕時,我想在一個php文件中插入和更新數據庫表。 我的插入查詢執行得很好,但是不會用列名狀態更新表。 我怎么做?
Eclipse代碼部分
爪哇
{
// somecode here
btndisapp=(Button)findViewById(R.id.btndisapp);
btndisapp.setOnClickListener(new View.OnClickListener(){
InputStream is=null;
@Override
public void onClick(View arg0){
// TODO Auto-generated method stub
//String phone=Integer.toString();
String name=""+tvname.getText().toString();
String purpose=""+tvpurpose.getText().toString();
String tfrom=""+tvtfrom.getText().toString();
String job=""+tvjob.getText().toString();
String tto=""+tvtto.getText().toString();
String dfrom=""+tvdfrom.getText().toString();
String dto=""+tvdto.getText().toString();
List<NameValuePair>nameValuePairs=new ArrayList<NameValuePair>(7);
nameValuePairs.add(new BasicNameValuePair("name",name));
nameValuePairs.add(new BasicNameValuePair("purpose",purpose));
nameValuePairs.add(new BasicNameValuePair("tfrom",tfrom));
nameValuePairs.add(new BasicNameValuePair("job",job));
nameValuePairs.add(new BasicNameValuePair("tto",tto));
nameValuePairs.add(new BasicNameValuePair("dfrom",dfrom));
nameValuePairs.add(new BasicNameValuePair("dto",dto));
//nameValuePairs.add(new BasicNameValuePair("item",item));
try{
HttpClient httpClient=new DefaultHttpClient();
HttpPost httpPost=new HttpPost("http://10.0.2.2/test/adddisappod.php");
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
//ArrayList<NameValuePair> nameValuePairs1 = new ArrayList<NameValuePair>();
//nameValuePairs.add(new BasicNameValuePair("id",id));
HttpResponse response=httpClient.execute(httpPost);
HttpEntity entity=response.getEntity();
is=entity.getContent();
String msg="Dispproved";
Toast.makeText(getApplicationContext(),msg,Toast.LENGTH_LONG).show();
}
catch(ClientProtocolException e)
{
Log.e("ClientProtocol","Log_tag");
e.printStackTrace();
}
catch(IOException e)
{
Log.e("Log_tag","IOException");
e.printStackTrace();
}
}
});
}
PHP文件
<?php
<error_reporting(E_ALL ^ E_DEPRECATED);
$con=mysql_connect('localhost','root','');
if(!$con)
{
die('Could not connect: '. mysql_error());
}
mysql_select_db("test",$con);
$name=$_POST['name'];
$job=$_POST['job'];
$purpose=$_POST['purpose'];
$dfrom=$_POST['dfrom'];
$tfrom=$_POST['tfrom'];
$dto=$_POST['dto'];
$tto=$_POST['tto'];
$ename=$_GET['name'];
mysql_query("insert into odattended
(ename, ejob, selectjob, purpose, datefrom,
dateto, timefrom, timetill, status)
values('{$name}', '{$job}', '{$job}', '{$purpose}',
'{$dfrom}', '{$dto}', '{$tfrom}', '{$tto}',
'disapproved')"
);
mysql_query("update od
SET status='disapproved'
where ename='."$name."'");
mysql_close();
?>
檢查您的語法。 正確的更新查詢:
mysql_query("update od SET status='disapproved' where ename='$name'");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.