为什么会出现意外错误

时间:2011-05-19 09:59:05

标签: java php android

<?php
$title = $_POST['title']; 
$date = $_POST['date'];
$time = $_POST['time'];
$channel = $_POST['channel'];
mysql_connect("localhost","root","");
mysql_select_db("imammuda");
$sql=mysql_query("insert into Program (ID, Title, Date, Time, Channel) values ('NULL', $title, $date, $time, $channel);
mysql_close();
?>

这是我插入数据的POST

private void adddataintophp(String title, String date, String time, String channel){
    ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    //http post
    try{
        nameValuePairs.add(new BasicNameValuePair("title", title));
        nameValuePairs.add(new BasicNameValuePair("date", date));
        nameValuePairs.add(new BasicNameValuePair("time", time));
        nameValuePairs.add(new BasicNameValuePair("channel", channel));
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://10.0.2.2/insertprogram.php");
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        is = entity.getContent();
    }catch(Exception e){
        Log.e("log_tag", "Error in http connection"+e.toString());
    }
}

运行php时,它给了我

Parse error: syntax error, unexpected $end in C:\wamp\www\InsertProgram.php on line 10

我不知道为什么它不能结束。

请在POST那里帮助我,我觉得那里有一些我没有找到它的错误。

4 个答案:

答案 0 :(得分:9)

使用)"

关闭此SQL查询
$sql=mysql_query("insert into Program (ID, Title, Date, Time, Channel) values ('NULL', $title, $date, $time, $channel)");

答案 1 :(得分:6)

关闭双引号并将列值放在单引号中

$sql=mysql_query("insert into Program (ID, Title, Date, Time, Channel) 
                values ('NULL', '$title','$date', '$time', '$channel'");

附注:在将用户输入发送到mysql服务器之前转义用户输入。

答案 2 :(得分:2)

$sql=mysql_query("insert into Program (ID, Title, Date, Time, Channel) values ('NULL', $title, $date, $time, $channel)");

你忘了结束语。

答案 3 :(得分:1)

mysql_query("insert into Program (ID, Title, Date, Time, Channel) values ('NULL', $title, $date, $time, $channel);

您没有结束SQL-String。添加“在字符串的末尾。