2013-05-02 49 views
1

我试图更新数据库中的字段但是从我的PHP页面越来越不确定变量的误差值...未定义变量的错误,同时更新在Android

我的代码是:

Intent myintent = getIntent(); 
    //mdate = intent.getStringExtra("mdate"); 
    //Toast.makeText(getApplicationContext(), mdate.toString(), Toast.LENGTH_LONG).show(); 
    title=(EditText)findViewById(R.id.editText1); 
    Bundle extras = getIntent().getExtras(); 
    if(extras != null){ 
     mtitle = extras.getString("title"); 
     stime = extras.getString("mtime"); 
     sdate = extras.getString("mdate"); 
     cvenue = extras.getString("venue"); 
    } 

    title.setText(mtitle); 
    title.setFocusable(false); 
    cdate=(EditText)findViewById(R.id.editText2); 
    cdate.setText(sdate); 
    cdate.setFocusable(false); 
    venue=(EditText)findViewById(R.id.editText4); 
    venue.setText(cvenue); 
    venue.setFocusable(false); 
    ctime=(EditText)findViewById(R.id.editText3); 
    ctime.setText(stime); 
    ctime.setFocusable(false); 
    fdate=cdate.getText().toString(); 
    ftime=ctime.getText().toString(); 
    ftitle=title.getText().toString(); 
    fvenue=venue.getText().toString(); 
    fattend=uid.toString(); 

    cnfrm=(Button)findViewById(R.id.button1);  
    cnfrm.setOnClickListener(new View.OnClickListener() 
    { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      try 
      { 
       String str_params=URLEncoder.encode("res="+resy.toString()+ 
         "&title="+ftitle+ 
         "&venue="+fvenue+ 
         "&cdate="+fdate+ 
         "&ctime="+ftime+ 
         "&attend="+fattend,"UTF-8");      
       get= new HttpGet("http://10.0.2.2/meetingschedular/confirmmeet.php?"+str_params);       
       client= new DefaultHttpClient(); 
       res=client.execute(get); 
       in=res.getEntity().getContent(); 
       StringBuffer str= new StringBuffer();      
       int ch; 
       while((ch=in.read())!=-1) 
        { 
         str.append((char)ch); 
        } 
      String tmp=str.toString(); 
      tmp=tmp.trim(); 
      //txt.setText(tmp); 
      Toast.makeText(getApplicationContext(), tmp, Toast.LENGTH_LONG).show(); 
      if(flag.equals(tmp)) 
       { 
        Toast.makeText(getApplicationContext(), tmp, Toast.LENGTH_LONG).show(); 
       } 
       else 
       { 
        Toast.makeText(getApplicationContext(), "Sorry cannot confirm", Toast.LENGTH_LONG).show(); 
       } 
      } 
      catch(Exception e) 
       { 
       Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_LONG).show(); 

       } 
     } 
    }); 

而且我的PHP代码:

<?php 
// Connects to your Database 
$con=mysql_connect('localhost','root',''); 
mysql_select_db('meetingschedulardata',$con); 
if(!$con) 
{ 
die("can not connect".mysql_error()); 
} 
if (isset($_GET['title'])) 
{ 
    $title=$_GET['title']; 
} 
if(isset($_GET['cdate'])) 
{ 
    $cdate=$_GET['cdate']; 
} 
if(isset($_GET['ctime'])) 
{ 
    $ctime=$_GET['ctime']; 
} 
if(isset($_GET['attend'])) 
{ 
    $attend=$_GET['attend']; 
} 
if(isset($_GET['venue'])) 
{ 
    $venue=$_GET['venue']; 
} 
if(isset($_GET['res'])) 
{ 
    $res=$_GET['res']; 
} 
$sdate = strtotime($cdate); 
$new_date = date('Y-m-d', $sdate); 
$stime = strtotime($ctime); 
$new_time = date('h:i:s', $stime); 
//echo "till now it works.."; 
$order="Update meetingdetails SET status='$res' WHERE status IS NULL AND title='$title' AND mdate='$new_date' AND mtime='$new_time' AND attendees='$attend' AND venue='$venue'"; 
$result=mysql_query($order,$con); 
//echo "It still works"; 
if($result==1) 
{ 
echo "true"; 
} 
else{ 
echo "false".mysql_error(); 
} 
mysql_close($con); 
?> 

我想更新我的分贝我的状态字段,但不能做.. 错误的表现是这样

enter image description here

PLS建议我一些东西,这样我可以提前正确运行我的应用程序...日Thnx

+0

什么是你的Java str_params的价值,你发送请求前? – karmafunk 2013-05-02 11:01:34

+0

首先定义您的所有变量空值或初始化它们或关闭通过php.ini的PHP警告 – 2013-05-02 11:02:31

+0

没有我编码所有的值,并把它放入str_params .... @karmafunk – priya89 2013-05-02 11:05:10

回答

0

检查你是从Android的传递哪些变量,哪些是你正在使用的服务器端的PHP码。 使用print_r($ _ REQUEST)从php端检查它;出口;在页面的开始。 这将帮助你调试,你可以从android传递的变量列表。

如果所有的罚款和相同的变量,你从它得到的,那么它将没有问题,你在严重的一面。

谢谢:) Kuldip