开发者

why get unexpected error?

<?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();
?>

this is my POST to insert data

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());
    }
}

when run the php, it gave me

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

i don't know why it cannot end.

please help me in the POST ther开发者_如何学编程e too, i think got some errors there that i did not found it.


close this sql query with )"

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


Close the double quote and put column values in single quotes

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

A side note: Escape user inputs before sending them to mysql server.


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

You forgot the end quote.


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

You didn't end the SQL-String. Add " on the end of the String.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜